Open submenu after clicking main menu

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">'
      );                   
      ?>

Gast

Quote from: dbs on March 10, 2018, 03:36:21 PM
<?php
show_menu2 
(
    
0SM2_ROOTSM2_ALLSM2_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">'
    
);


a-tag without href-attribute is invalid, use
<a href="#">[menu_title]</a>
instead of the simple <a>
Quote
if (class == menu-expand && level == 0)

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


dbs

Hi, for code please use in the editor the code button #
Have you tried TRIM?
<?php
show_menu2 
(
    
0SM2_ROOTSM2_ALLSM2_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">'
    
);


If this not work, tell more about what a menu you have and want.
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

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">'
    );
    ?>