子子菜单步行法

时间:2014-03-14 06:05:27

标签: wordpress wordpress-theming

我有一个适用于我的子菜单的助行器类但是如何将子子菜单项放入此代码中?

下面是我的代码

的functions.php

<?php    
class wp_submenu_class extends Walker_nav_menu {    
  function start_lvl(&$output, $depth) {    
    $indent = str_repeat("\t", $depth);    
    $output .= "\n$indent<ul class=\"submenu\">\n";    
  }    
}   
?>

的header.php

<div class="navi">
<?php  wp_nav_menu( array(    
    'menuitems' => 'mymenu',    
    'container'       => '',     
    'container_id'    => '',    
    'menu_class'      => 'topmenu',    
    'menu_id'         => '',    
    'items_wrap'      => '<ul id="" class="%2$s">%3$s</ul>',    
    'walker' => new wp_submenu_class() ));     
 ?>    
</div>

1 个答案:

答案 0 :(得分:0)

  

你没有为你的班级指定一个end_lvl。

<?php  wp_nav_menu( array(    
                        'menu' => 'Menu 1',  // REPLACE NAME WITH YOUR MENU
                        'container_class' => 'menu-header',
                        'menu_class' => 'nav-menu',
                        'depth'=> 3, // CHANGE THE VALUE WHICH LAVEL YOU CAN DISPLAY.
                        'menuitems' => 'mymenu',    
                        'container'       => '',     
                        'container_id'    => '',    
                        'menu_class'      => 'menu-header', // MENU CLASS   
                        'menu_id'         => '',    
                        'items_wrap'      => '<ul id="" class="%2$s">%3$s</ul>',    
                        'walker' => new wp_submenu_class() //function
                        ));     
?>

class wp_submenu_class extends Walker_Nav_Menu {
  function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class=\"submenu\">\n";
  }
  function end_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "$indent</ul>\n";
  }
}

enter image description here

enter image description here