如何使用wp_NAV_MENU()创建此菜单?

时间:2017-06-29 作者:user2584538

我怎样才能用wp_nav_menu()? 此菜单是使用引导创建的。

<ul id="menu-main_menu" class="nav navbar-nav navbar-center">
    <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-5 current_page_item menu-item-8">
        <a href="#">Home</a>
    </li>
    <li  id="menu-item-25" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-25 dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About Us <span class="caret"></span></a>
            <ul class="dropdown-menu">
                <li>
                    <a href="#">Our Founders</a>
                </li>
                <li>
                    <a href="#">Our Vision</a>
                </li>
                <li>
                    <a href="#">Our Strategy</a>
                </li>
                <li>
                    <a href="#">How We Work</a>
                </li>
            </ul>
    </li>
    <li id="menu-item-26" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-26 dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Projects <span class="caret"></span></a>
            <ul class="dropdown-menu">
                <li>
                    <a href="#">Our Projects</a>
                </li>
                <li>
                    <a href="#">Past Projects</a>
                </li>
                <li>
                    <a href="#">Current Projects</a>
                </li>
            </ul>
    </li>
    <li id="menu-item-27" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-27">
        <a href="#">News &amp; Events</a>
    </li>
    <li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30">
        <a href="#">Contact</a>
    </li>
</ul>

1 个回复
最合适的回答,由SO网友:user2584538 整理而成

这可以通过nav walker. 我用过this. 我是按照上面提到的步骤走的。

放置navwalker (wp-bootstrap-navwalker.php) 在您的theme rootnavwalker 在里面functions.php 文件require_once(\'wp-bootstrap-navwalker.php\');Appearance -> Menus)header.php

wp_nav_menu( array(
  \'menu\' => \'main_menu\',
  \'depth\' => 2,
  \'container\' => false,
  \'menu_class\' => \'nav navbar-nav navbar-center\',
  \'walker\' => new wp_bootstrap_navwalker())
);
`main_menu` is my menu name

结束