1
trabis
Hacking multimenu for showing selected menus
  • 2008/1/20 14:34

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Hi,

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

Yesterday I 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)

To take a quick look just visit http://www.luso-poemas.net

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:

<
div class="menuhcss">

<{
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}>
            
            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>
        

<{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}>
    
    li>
    ul>
    <{/if}>

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!

2
Anonymous
Re: Hacking multimenu for showing selected menus
  • 2008/1/20 15:03

  • Anonymous

  • Posts: 0

  • Since:


Cool hack I will use it soon.

3
trabis
Re: Hacking multimenu for showing selected menus
  • 2008/1/22 14:07

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Hi Mowaffak, I´m glad you found it useful!
Please report bugs if any.
Thanks

Login

Who's Online

157 user(s) are online (89 user(s) are browsing Support Forums)


Members: 0


Guests: 157


more...

Donat-O-Meter

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

Latest GitHub Commits