例如我想创建这个菜单:
<div class="menu_wrap">
<ul class="nav sf-menu">
<li class="sub-menu"><a href="">Main Menu 1</a>
<ul>
<li><a href=""><span>-</span>Sub Menu 1</a></li>
<li><a href=""><span>-</span>Sub Menu 2</a></li>
</ul>
</li>
<li class="sub-menu"><a href="">Main Menu 2</a>
<ul>
<li><a href=""><span>-</span>Sub Menu 1</a></li>
<li><a href=""><span>-</span>Sub Menu 2</a></li>
</ul>
</li>
<li><a href="">Main Menu 3 without sub menu</a></li>
</ul>
如何添加class =&#34;子菜单&#34;在li标签中,如果子菜单存在:
<li class="sub-menu"><a href="">Main Menu 1</a>
如果不存在echo li而没有class =&#34;子菜单&#34; :
<li><a href="">Main Menu 3 without sub menu</a></li>
我有这个代码用于functions.php:
//Adds Menus
add_theme_support( 'menus' );
register_nav_menus(
array(
'mainmenu' => 'The Main Menu'
)
);
function dtuts_main_nav() {
// display the wp3 menu if available
wp_nav_menu(array(
'theme_location' => 'mainmenu',
'menu' => 'mainmenu',
'container' => 'div',
'container_class' => 'menu_wrap',
'menu_class' => 'nav sf-menu',
'echo' => true,
'items_wrap' => '<ul class="%2$s">%3$s</ul>',
'depth' => 1,
'walker' => new themeslug_walker_nav_menu
));
}
我无法写出themeslug_walker_nav_menu课程,请帮忙。