1
tripmon
Semi-Dynamic Horizontal Menu code for your theme.
  • 2006/3/1 21:23

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


Just posting this as a courtesy as I had a difficult time finding any info on this subject in the forums.

-Tested on 2.2.x ONLY-
(but I don't think there would be an issue with earlier versions.)

While it's easy enough to hardcode a menu into your theme, many would prefer a more dynamic menu.

I poked around with multimenu and some other (Javascript/flash) solutions, but was not getting exactly what I was looking for. Using the code from the myxoops DW extension, I have cobbled the following code together.

It will disply sublinks exactly as the XOOPS main menu block does for each module in a SEO friendly manner.

You will need to edit the code in order to use it, but basically, once you set the main links up, the code will dynamically call any sublinks for the module you are in and display them beneath the main menu... (hence semi-dynamic).

The original myxoops code(thanks POD) had some formatting that was not working well for me (Table structure was whaking out my css) as well as some user/admin menu options which I was not going to use (I use the user menu as a block in conjunction with this.)

I'll post the code, then explain a bit more.

The first portion should be inserted in the header, right before the body tag (you could also include it in header.php if you wanted.

<{php}>global $xoopsModule $xoopsUser ;
$xoops_url XOOPS_URL ;
$submenu_str ="";
$mainmenu_str ="
<a href='
$xoops_url/'>Home</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/ams/'>Articles</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/shoalscontent0/'>News</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/newbb/'>Forums</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/calendar/'>Calendar</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/xcgal/'>Photos</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/xdirectory/'>Directory</a>&nbsp;|&nbsp;<a href='$xoops_url/_sl/modules/myads/'>Classifieds</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/freecontent/'>Guides</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/xp-weather/'>Weather</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/xmovietime/'>Movies</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/mylinks/'>Links</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/friendfinder/'>Friends</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/smartfaq/'>FAQ</a>&nbsp;|&nbsp;<a href='$xoops_url/modules/sitemap/'>SiteMap</a>
"
;
if( isset( 
$xoopsModule )&&is_object$xoopsModule ) ) {
    
$dirname $xoopsModule->getVar'dirname' ) ;
    
$mainmenu_str str_replace("/modules/$dirname/'","/modules/$dirname/'"$mainmenu_str ) ;
    
$sublinks =&$xoopsModule->subLink();
    if( 
count$sublinks )>) {
        
$submenu_str .="<br />";
            foreach( 
$sublinks as $sublink ) {
                
$submenu_str .="<a href='$xoops_url/modules/$dirname/{$sublink['url']}'>{$sublink['name']}</a>&nbsp;|&nbsp;";
            }
            
$submenu_str .="<br />";
} else {
$submenu_str .="&nbsp;";
    }
}<{/
php}>


OK, the 4th line:
$mainmenu_str ="<a ref='$xoops_url/'>Home</a>

is the first complete entry.

Using the format above add/remove any main links you would like to display making sure to use the actual directory names of your install. (the &nbsp;| code which follows is a seperator, remove if you wish).

Here, we are setting up a string which we will call for diisplay later in our theme. I broke it up this way to allow a single line of code to be inserted for display making it easier to fit into your theme.

Using the format above add/remove any main links you would like to display.

Once you have specified your menu items as described above insert the following code into your theme where you would like the menu to appear.
<{php}>
echo 
$mainmenu_str ;
echo 
$submenu_str ;
<{/
php}>


you can string the above together like this to make it easier to edit your theme in a wysiwyg editor:
Quote:
<{php}>echo $mainmenu_str ; echo $submenu_str ;<{/php}>


Now all you have to do is style it however you want.

FYI to apply a style, add a class tag to the a href tag to the string in the header... EG:

To apply a style called sublinks (which you have defined as a class in your theme's CSS) to the sublinks you would add class='yourclasshere' to the code in the head section. In the example below, the ****> is emphasising where the code change is, do not include the stars and brackets.

foreach( $sublinks as $sublink ) {$submenu_str .="<a *****>class='sublinks'<**** href='$xoops_url/modules/$dirname/{$sublink['url']}'>{$sublink['name']}</a>&nbsp;|&nbsp;";


I prefer to center the code which will present any sublinks that the module has beneath the main menu in the center. You can kick it around a bit.

Good luck and have fun.

2
tripmon
Re: Semi-Dynamic Horizontal Menu code for your theme.
  • 2006/3/7 20:04

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


OOOOps,

Forgot to add:
Once you have your theme designed & working, you should move the php code string out of the head and into the very top of the body before deploying.

It will still work in the head, but is's non-compliant and may cause issues.

3
wizanda
Re: Semi-Dynamic Horizontal Menu code for your theme.
  • 2006/3/7 22:33

  • wizanda

  • Home away from home

  • Posts: 1585

  • Since: 2004/3/21


Wow Thanxz I may try that!

Half the post you find are mine on menu systems

Is there anyway to incorparte this in to a module also?

As I don't like my current one
and would really like to have a full XOOPS system :)

There are also php MySQL gpl systems if you want me to find the link for them?

As couldn't we have it in admin, a menu system? That could be used for drop down menus ect?

4
tripmon
Re: Semi-Dynamic Horizontal Menu code for your theme.
  • 2006/3/7 22:47

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


Hey Wizanda,

You could incorp., but then you would not be able to display the menu above the blocks without manually adding code to the theme itself(ala multi menu).

So, if you're going to add code to the theme anyway.....

BTW the sub-menu's are displayed on click not hover as coded.

Let me know if you try it out.

Login

Who's Online

153 user(s) are online (102 user(s) are browsing Support Forums)


Members: 0


Guests: 153


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits