WebsiteBaker Support (2.11.x) > General Help & Support

Open submenu after clicking main menu

(1/1)

henri:
Is there a way to change the code below so that the submenu only appears after a mouse click on the main menu item.

<? php
show_menu2 (
0, SM2_ROOT, SM2_ALL, SM2_ALL,
'
* [if (class == menu-expand && level == 0) {<a> [menu_title] </a>} else {<a href="[url]"> [menu_title] </a> }] ',' </ li> ',
false,
false,
false,
'<ul class = "nav-menu" id = "main-navigation">'
);
?>

dbs:
Hi, for code please use in the editor the code button #
Have you tried TRIM?

--- Code: ---<?php
show_menu2 (
    0, SM2_ROOT, SM2_ALL, SM2_TRIM,
    '[if (class == menu-expand && level == 0) {<a> [menu_title] </a>} else {<a href="[url]"> [menu_title] </a> }] ',' </ li> ',
    false,
    false,
    false,
    '<ul class = "nav-menu" id = "main-navigation">'
    );

--- End code ---

If this not work, tell more about what a menu you have and want.

Gast:

--- Quote from: dbs on March 10, 2018, 03:36:21 PM ---<?php
show_menu2 (
    0, SM2_ROOT, SM2_ALL, SM2_TRIM,
    '[if (class == menu-expand && level == 0) {<a> [menu_title] </a>} else {<a href="[url]"> [menu_title] </a> }] ',' </ li> ',
    false,
    false,
    false,
    '<ul class = "nav-menu" id = "main-navigation">'
    );


--- End quote ---

a-tag without href-attribute is invalid, use

--- Code: ---<a href="#">[menu_title]</a>
--- End code ---
instead of the simple <a>

--- Quote ---if (class == menu-expand && level == 0)
--- End quote ---

means: this code behind my quote works only, if an link has at minimum one child (condition: class == menu-expand=
if you need it for all links in the first level of the visible menu, use the level-condition only

HINT: level 0 (zero) is the root of WB and this example works only, if you want to display this root pages (specially for single language pages). Be sure, that you use your favorite level in the condition

henri:
Different combinations tried.
The combination below works best but if I use the mouse on the item in the main menu, then the submenu appears immediately.
The submenu should appear after clicking on item in main menu.

<?php
show_menu2(
0,SM2_ROOT, SM2_ALL, SM2_ALL,
'
* [if (condition:class==menu-expand && level==0) {<a href>[menu_title]</a>} else {<a href="[url]"> [menu_title] </a> }] ',' </ li> ',
false,
false,
false,
'<ul class="nav-menu" id="main-navigation">'
);                   
?>

If I use the code below, no submenu will appear after a mouse click on the main menu item.
If I set the value of level == 0 to 1, the submenu will appear but in the main menu the item that I click with the mouse will also open. What is not the intention.

<?php
show_menu2(
0,SM2_ROOT, SM2_ALL, SM2_TRIM,
'
* [if (condition:class==menu-expand && level==0) {<a href="#">[menu_title]</a>} else {<a href="[url]"> [menu_title] </a> }] ',' </ li> ',
false,
false,
false,
'<ul class="nav-menu" id="main-navigation">'
);                   
?>

Navigation

[0] Message Index

Go to full version