WebsiteBaker Support (2.8.x) > Templates, Menus & Design

ShowMenu2: Bootstrap Navigation

<< < (4/9) > >>

casi:
Hi. I am using this menu for my template. works fine, but when I add another menu block the functionality seems not to work anymore.

$menu[1]='Main';
$menu[2]='Top';

The 'Main' menu with the ID 1 works fine, but as soon I use the 'Top' menu with the ID 2, this 'Top' menu is empty, not displayed anymore. Can you help on this?


--- Code: ---<?php
// Top Navigation
ob_start(); 
$topnav = str_replace('menu-current','active',$topnav);
show_menu2(
$aMenu          = 2,
$aStart         = SM2_ROOT+1, 
$aMaxLevel      = SM2_START,
$aOptions       = SM2_PRETTY,
$aItemOpen      = '<li>[ac][menu_title]</a>',
$aItemClose     = '</li>',
$aMenuOpen      = '<ul>',
$aMenuClose     = '</ul>',
$aTopItemOpen   = false,
$aTopMenuOpen   = false
);
$topnav = ob_get_contents();
ob_end_clean();
// end Top Navigation


// Main Navigation
ob_start(); 
$mainnav = str_replace('menu-current','active',$mainnav);
show_menu2(
$aMenu          = 1,
$aStart         = SM2_ROOT+1, 
$aMaxLevel      = SM2_CURR+1,
$aOptions       = SM2_ALL,
$aItemOpen      = '<li class="[if(class=menu-current||class=menu-parent){active}] [if(class==menu-expand){dropdown}]">[if(class==menu-expand){<a href="[url]" class="dropdown-toggle" data-toggle="dropdown">[menu_title] <b class="caret"></b></a>}else {<a href="[url]">[menu_title]</a>}]',
$aItemClose     = '</li>',
$aMenuOpen      = '<ul class="[if(level==1){nav navbar-nav} else {dropdown-menu}]">',
$aMenuClose     = '</ul>',
$aTopItemOpen   = false,
$aTopMenuOpen   = false
);
$mainnav = ob_get_contents();
ob_end_clean();
// end Main Navigation
?>
--- End code ---

Thanks Casi

DarkViper:

--- Quote from: casi on March 20, 2015, 07:54:23 AM ---Hi. I am using this menu for my template. works fine, but when I add another menu block the functionality seems not to work anymore.

$menu[1]='Main';
$menu[2]='Top';

The 'Main' menu with the ID 1 works fine, but as soon I use the 'Top' menu with the ID 2, this 'Top' menu is empty, not displayed anymore. Can you help on this?


--- Code: ---<?php
// Top Navigation
ob_start(); 
$topnav = str_replace('menu-current','active',$topnav);
show_menu2(
$aMenu          = 2,
...
);
$topnav = ob_get_contents();
ob_end_clean();

--- End code ---

--- End quote ---
this can not work, because you try to replace the class names before the menu is calculated.

A more simple solution without str_replace():

--- Code: ---<?php
// Top Navigation
$topnav = show_menu2(
    $aMenu          = 2,
    $aStart         = SM2_ROOT+1, 
    $aMaxLevel      = SM2_START,
    $aOptions       = SM2_PRETTY|SM2_BUFFER,
    $aItemOpen      = '<li class="[class][if(class=menu-current||class=menu-parent){ active}]">[ac][menu_title]</a>',
    $aItemClose     = '</li>',
    $aMenuOpen      = '<ul>',
    $aMenuClose     = '</ul>',
    $aTopItemOpen   = false,
    $aTopMenuOpen   = false
);
// end Top Navigation

// Main Navigation
$mainnav = show_menu2(
$aMenu          = 1,
$aStart         = SM2_ROOT+1, 
$aMaxLevel      = SM2_CURR+1,
$aOptions       = SM2_ALL|SM2_BUFFER,
$aItemOpen      = '<li class="[if(class=menu-current||class=menu-parent){active}] [if(class==menu-expand){dropdown}]">[if(class==menu-expand){<a href="[url]" class="dropdown-toggle" data-toggle="dropdown">[menu_title] <b class="caret"></b></a>}else {<a href="[url]">[menu_title]</a>}]',
$aItemClose     = '</li>',
$aMenuOpen      = '<ul class="[if(level==1){nav navbar-nav} else {dropdown-menu}]">',
$aMenuClose     = '</ul>',
$aTopItemOpen   = false,
$aTopMenuOpen   = false
);
// end Main Navigation

--- End code ---

have a nice day
Manuela

macsmet:
Hi,

Just playing with Bootstrap and using this menu code to get the Bootstrap menu working.
How can I limit WB showing the third level in the Bootstrap menu?
It doesn't actually work but it show there are more pages (class="caret" shows up) and it makes the second level not responding anymore.



nibz:
Hi there Macsmet,

I missed your question (forum is a little busy  :-))

But to answer it:

You could add another conditional statement to check if the menu level is less then 1 then the next level will not show.

Here my updated code:

--- Code: ---<nav class="navbar navbar-default" role="navigation">
<?php 
$open = '<li class="[if(class=menu-current||class=menu-parent){active}] [if(class==menu-expand){dropdown}]">
[if(class==menu-expand&&level<1){<a href="[url]" class="dropdown-toggle" data-toggle="dropdown">[menu_title] <b class="caret"></b></a>}else {<a href="[url]">[menu_title]</a>}]';
show_menu2(
$aMenu          = 1,
$aStart         = SM2_ROOT, 
$aMaxLevel      = SM2_CURR+1,
$aOptions       = SM2_ALL,
$aItemOpen      = $open,
$aItemClose     = '</li>',
$aMenuOpen      = '<ul class="[if(level==0){nav navbar-nav} else {dropdown-menu}]">',
$aMenuClose     = '</ul>',
$aTopItemOpen   = false,
$aTopMenuOpen   = false
);?>
</nav>

--- End code ---

Notice the if(class==menu-expand&&level<1) this checks if the level is not more than 1 and will not place the caret on the first level items, only on the root level.

Hope this answers your question,

Please let me know if it does or doesn't

macsmet:
Hi Nibz,

Your addition to the code works fine.
Thanks.

greetings,

MacSmet

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version