Xuups
Get an account!     Login

Utilities

Main menu

Who's Online

18 user(s) are online (1 user(s) are browsing Hacks and Tips)

Members: 0
Guests: 18

more...

Get Xoops

Support Xuups Project

Modules :  Hacking Multimenu - Selected menus
Tags: hack   multimenu   menus  
 
Hi,

I love multimenu but I miss one important feature, when I hit a menu link then link should be turned to selected.

I've hacked multimenu so here's what the hack does:

When you click a mainmenu it highlights the mainmenu
When you click a submenu it highlights the correspondig mainmenu
When you browse your site in pages that aren't linked directly in the menu it highlights the corresponding module menu.
If theres is no corresponding module menu than it highlights a default menu (Home for example, but you can change it)

You can take a look in this very site!

So here's what to do:
Go to modules/multiMenu/blocks/block.php

At the end find:
$block['contents'][] = $imenu

// Sublinks
// Groups
}

return 
$block;
?>


And replace with this:
//start of hack by trabis for selected menus
$imenu['id'] = $myrow['id'];
$imenu['pid'] = $myrow['pid'];

$block['contents'][] = $imenu

// Sublinks
// Groups
}


//get the currentpage
$query_string $_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:'';
$self 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$query_string;
//set a default page in case we don't get matches
$default XOOPS_URL."/index.php";

//get all the links that could fit into this pageplus the default link
$i 0;
foreach (
$block['contents'] as $menu){
    
$link $menu['linkurl'];
    
$selected eregi($menu['linkurl'], $self)? 10;
    
$selected = ($menu['linkurl'] == $self) ? 1$selected;
    
$selected = ($menu['linkurl'] == $default) ? 1$selected;
    
$block['contents'][$i]['selected'] = $selected;
    
$i++;
}

//From those links get only the longer one
$i 0;
$issub 0;
foreach (
$block['contents'] as $this_menu){
    
$other 0;
    foreach (
$block['contents'] as $other_menu){
        if(
$this_menu['selected']==&& $other_menu['selected']==1){
            if (
strlen($other_menu['linkurl']) < strlen($this_menu['linkurl'])){
                
$block['contents'][$other]['selected'] = 0;
                
$issub $this_menu['submenu'];
                
$subid $this_menu['id'];
                
$subord $i;
            }
        }
        
$other++;
    }
    
$i++;
}

//if the longer link is in a sub menu than change selection to the parent menu
if ($issub == 1){
    
//get the parent menu
    
$sql =     "SELECT id, pid, groups, link, submenu, title, target, imageurl, weight
       FROM "
.$xoopsDB->prefix('multimenu').$options[15]."
    WHERE id="
.$subid;
    
$result $xoopsDB->queryF($sql);
    
$myrow $xoopsDB->fetchArray($result);

    
$i 0;
    foreach (
$block['contents'] as $mainmenu){
        
//changing selections
        
if ($mainmenu['id'] == $myrow['pid']){
            
$block['contents'][$i]['selected'] = 1;
            
$block['contents'][$subord]['selected'] = 0;
        }
        
$i++;
    }
}
//end of hack by trabis for selected menus

return $block;
?>


Ok, now you have an extra variable to use in your templates
<{if $imenu.selected}>add your class here<{/if}>

Here is an example for multimenu_dyn_horiz_css.html:
<!-- Start multiMenu <{$block.mm}> -->
<
div class="menuhcss">
<!-- 
Start multiMenu <{$block.mm}> -->
<{
assign var=ul_main value=0}>
<{
assign var=ul_sec  value=0}>

<{foreach 
item=imenu from=$block.contents}>
<{if 
$imenu.submenu == 0}>
<{if 
$ul_sec == 1}></ul><{assign var=ul_sec value=0}><{/if}>
    <{if 
$ul_sec == 1}><{assign var=ul_sec value=0}><{/if}>
        <{if 
$ul_main == 1}>
            <!--[if 
lte IE 6]>
            </
td></tr></table>
            </
a>
            <![endif]-->
            </
li>
            </
ul>
            <{
assign var=ul_main value=0}>
        <{/if}>
        <{if 
$ul_main == 0}>
            <{
assign var=ul_main value=1}>
        <{/if}>

        <
ul>
        <
li>
        <
<{if $imenu.selected}>class="hide_selected"<{else}>class="hide"<{/if}><{if $imenu.linkurl}>href="<{$imenu.linkurl}>"<{/if}> title="<{$imenu.alt_title}>"><{$imenu.image}>&nbsp;<{$imenu.title}></a>
        <!--[if 
lte IE 6]>
        <
<{if $imenu.selected}>class="selected"<{/if}>href="<{$imenu.linkurl}>" title="<{$imenu.alt_title}>"><{$imenu.image}>&nbsp;<{$imenu.title}>
        <
table><tr><td>
        <![endif]-->

<{elseif 
$imenu.submenu == OR $imenu.submenu == 2}>
        <{if 
$ul_sec == 0}><ul><{assign var=ul_sec value=1}><{/if}>
        <
li><<{if $imenu.linkurl}>href="<{$imenu.linkurl}>"<{/if}> title="<{$imenu.alt_title}>"><{$imenu.image}>&nbsp;<{$imenu.title}></a></li>

<{elseif 
$imenu.submenu == 3}>
        <{if 
$ul_sec == 0}><ul><{assign var=ul_sec value=1}><{/if}>
        <
div><li><class="note" <{if $imenu.linkurl}>href="<{$imenu.linkurl}>"<{/if}> title="<{$imenu.alt_title}>"><{$imenu.image}>&nbsp;<{$imenu.title}></a></li></div>

<{elseif 
$imenu.submenu == 4}>
        <{if 
$ul_sec == 0}><ul><{assign var=ul_sec value=1}><{/if}>
        <
div><li><class="cat" <{if $imenu.linkurl}>href="<{$imenu.linkurl}>"<{/if}> title="<{$imenu.alt_title}>"><{$imenu.image}>&nbsp;<{$imenu.title}></a></li></div>

<{/if}>
<{/foreach}>
  <{if 
$ul_sec == 1}></ul><{/if}>
    <{if 
$ul_main == OR $ul_sec == 1}>
    <!--[if 
lte IE 6]>
    </
td></tr></table>
    </
a>
    <![endif]-->
    </
li>
    </
ul>
    <{/if}>
<!-- 
End multiMenu <{$block.mm}> -->
</
div>


You have to add the correspondig classes to the corresponding css, in my case I added class "selected" and "hide_selected".
In script/08/basic_dd.css:
.menuhcss ul li a.hide_selected, .menuhcss ul li a:visited.hide_selectedmenuhcss ul li a.selected, .menuhcss ul li a:visited.selected{
background-imageurl('http://www.luso-poemas.net/modules/multiMenu/templates/images/links_over.jpg');
background-repeatrepeat-x;
color#027AD2;
height20px
padding
0px;
}


In script/08/basic_dd_ie.css:

/* ignore the link used by 'other browsers' */
.menuhcss ul li a.hide, .menuhcss ul li a:visited.hide .menuhcss ul li a.hide_selected, .menuhcss ul li a:visited.hide_selected{
display:none;
}


That's it!


TDM

Author
trabis
Author trabis
News by the same authorMore stories
Author rssAuthor rss
StatisticsStatistics
 
Story
Date 2008/4/9 0:08:44
Views 5490
Favorites 2
Send this Story to a FriendSend
Printer Friendly PagePrint
Create a PDF from the articleCreate a pdf
 
Bookmarks
         
         
         
         
         
     
Recents
How to sucessfuly add scripts in your Xoops Themes
Query timers on debug for xoops 2.3
Highlighting current module on mainMenu
Main menu hack - on click submenus
Preventing empty blocks to display
Random
How to sucessfuly add scripts in your Xoops Themes
Query timers on debug for xoops 2.3
Highlighting current module on mainMenu
Adding an horizontal multiMenu to Xoops
Hacking Multimenu - Selected menus
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
Waqar
Posted: 2009/10/23 15:29  Updated: 2009/10/23 15:29
Just popping in
Joined: 2009/8/30
From:
Posts: 5
 Re: Hacking Multimenu - Selected menus
HI trabis i tried this hack with multimenu_dyn_horizontal.html. when i click the link it will highlight one back not the original link. can you help please., it working with dyn_horizontal_css.html but not with multimenu_dyn_horizontal.html
moss
Posted: 2009/11/10 13:28  Updated: 2009/11/10 13:58
Just popping in
Joined: 2009/11/10
From:
Posts: 1
 Re: Hacking Multimenu - Selected menus
I download last multimenu module and the tips can not be applied. There is no code like that :
Quote:
$block['contents'][] = $imenu; }
// Sublinks }
// Groups }
return $block; ?>


Any idea to apply to new multimenu ?
svetorim
Posted: 2010/9/16 0:29  Updated: 2010/9/16 0:29
Just popping in
Joined: 2010/9/16
From:
Posts: 1
 Re: Hacking Multimenu - Selected menus
Interesting!
aslani606
Posted: 2012/8/24 6:10  Updated: 2012/8/24 6:10
Just popping in
Joined: 2009/3/15
From:
Posts: 3
 Re: Hacking Multimenu - Selected menus
Hello

Where can I download the latest version of this module?(Multimenu)for xoops2.5.5

Thanks
 

Login

Username:

Password:

Remember me



Lost Password?

Register now!

Ajax Search


Advanced Search

Sub menu

Last comments