最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

walker - Displaying Nav Menu

programmeradmin0浏览0评论

I want to ask if this <?php wp_nav_menu( array('theme_location' => 'primary') ); ?> get all the sub-menu automatically? I saw this one of my downloaded theme and it displays all the submenu only using this and css code. I am curious why it display the submenu even though it doesn't uses walker class for example like this

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(),
) );

with another walker file like this . I am new to wordpress and I hope someone would enlighten me. Thanks

I want to ask if this <?php wp_nav_menu( array('theme_location' => 'primary') ); ?> get all the sub-menu automatically? I saw this one of my downloaded theme and it displays all the submenu only using this and css code. I am curious why it display the submenu even though it doesn't uses walker class for example like this

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(),
) );

with another walker file like this https://github/wp-bootstrap/wp-bootstrap-navwalker. I am new to wordpress and I hope someone would enlighten me. Thanks

Share Improve this question edited Nov 21, 2019 at 7:50 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 21, 2019 at 7:05 Lucifer LeviLucifer Levi 932 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Yes, wp_nav_menu displays all levels of menu by default.

You don't have to write your custom walker class to display submenu items - WordPress already has one which is used by default.

WP_Bootstrap_Navwalker is used only because given theme uses Bootstrap and nav menu should generate custom HTML code, which is compatible with Bootstrap.

The only thing you have to remember is that there is depth argument which decides how many levels of menu should be printed.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论