第二个菜单具有第一个菜单ID

时间:2014-02-22 作者:Bilal Khoukhi

我注册了两个菜单top menu和main menu。

我在管理面板上创建了两个菜单,并为每个菜单分配了一个菜单(不同的项目)

但当我查看前端时,我看到这两个菜单具有相同的项目,主菜单的id为“menu-top-menu-1”

以下是我所拥有的:

功能。php

function register_my_menus() {
    register_nav_menus (array(
        \'main-menu\' => \'Main Menu\',
        \'top-menu\' => \'Top Menu\',
    ));
}
add_action( \'init\', \'register_my_menus\' );
标题。php

顶部菜单:

 <div class=" top-menu-container">
        <?php wp_nav_menu(array(
            \'container\' => \'nav\',
            \'container_class\' => \'container\',
            \'item_location\' => \'top-menu\',
            \'menu_class\' => \'nav top-menu pull-right\',
        )); 
        ?>
 </div>
主菜单:

 <div class="container">
    <div class="logo col-xs-12 col-sm-12 col-md-3 col-lg-4">
        <a href="<?php echo home_url(); ?>"><img class="block-center " src="<?php print IMAGES; ?>/logo.png" alt="<?php bloginfo(\'name\'); ?> | <?php bloginfo(\'description\'); ?>"/></a>
    </div>
    <nav class="navbar navbar-default col-xs-12 col-sm-12 col-md-9 col-lg-8" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-menu-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse nav-wrap" id="main-menu-toggle">
        <?php wp_nav_menu(array(
            \'item_location\' => \'main-menu\', 
            \'container_class\' => \'collapse navbar-collapse nav-wrap\',
            \'container_id\' => \'main-menu-toggle\',
            \'menu_class\' => \'nav navbar-nav main-menu\',
        )); 
        ?>
        </div>
    </nav>
 </div>
这是顶部菜单和主菜单的渲染输出

<nav class="container">
    <ul id="menu-top-menu" class="nav top-menu pull-right">
        <li id="menu-item-4" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4"><a href="#">CanHerp</a></li>
        <li id="menu-item-5" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5"><a href="#">Rescues</a></li>
        <li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6"><a href="#">Breeders</a></li>
        <li id="menu-item-7" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"><a href="#">Forums</a></li>
    </ul>
</nav>

<div class="collapse navbar-collapse nav-wrap" id="main-menu-toggle">
  <div id="main-menu-toggle" class="collapse navbar-collapse nav-wrap">
    <ul id="menu-top-menu-1" class="nav navbar-nav main-menu">
      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4"><a href="#">CanHerp</a></li>
      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5"><a href="#">Rescues</a></li>
      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6"><a href="#">Breeders</a></li>
      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"><a href="#">Forums</a></li>
    </ul>
  </div>
</div>
我还想知道这是否是处理引导响应菜单(主菜单)的最佳方法。

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

从注释移动:您要查找的参数是theme_location, 不item_location.

SO网友:Mayur Devmurari

像这样注册菜单。。。

register_nav_menus( array(
        \'primary1\'   => __( \'Top primary menu First\', \'ank\' ),
        \'primary2\'   => __( \'Top primary menu Second\', \'ank\' ),
        \'secondary\' => __( \'Secondary menu in left sidebar\', \'ank\' ),
    ) );
并在这样的代码中使用。。。

<?php wp_nav_menu( array( \'theme_location\' => \'primary2\' ) ); ?>
使用item\\u location的theme\\u location瞬间。。。。。。

结束

相关推荐

注册_NAV_MENUS,然后以编程方式创建菜单

我有一个register_nav_menus 调用我的主题函数。php://register nav menu and footer nav. register_nav_menus( array( \'main-nav\' => \'Main Navigation\', \'footer-nav\' => \'Footer Navigation\' ) ); 这很好,但我想采取额外的步