我想问一下这个<?php wp_nav_menu( array('theme_location' => 'primary') ); ?>是否自动得到所有的子菜单?我看到了我下载的主题之一,它只使用这个和css代码显示所有的子菜单。我很好奇为什么它会显示子菜单,即使它不使用walker类,例如
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'navbar-nav mr-auto',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
) );使用像这个https://github.com/wp-bootstrap/wp-bootstrap-navwalker这样的另一个walker文件。我是wordpress的新手,我希望有人能启发我。谢谢
发布于 2019-11-21 07:56:16
是的,默认情况下,wp_nav_menu会显示所有级别的菜单。
您不必编写自定义的walker类来显示子菜单项-- WordPress已经具有默认使用的一。
使用WP_Bootstrap_Navwalker只是因为给定的主题使用引导和nav菜单应该生成自定义的HTML代码,这是与引导兼容的。
唯一需要记住的是,存在depth参数,它决定应该打印多少级别的菜单。
https://wordpress.stackexchange.com/questions/352996
复制相似问题