WP_NAV_MENU未选择正确的菜单

时间:2015-03-10 作者:Ariel

我有个奇怪的问题。我有两个菜单,并在函数中注册了它们。php,如下所示:

add_theme_support( \'menus\' );
register_nav_menu( \'primary\', \'Top Nav\' );
register_nav_menu( \'footer\', \'Footer\' );
在我的标题中,我有以下代码

<?php
    wp_nav_menu(array(
    \'menu\' => \'Top Nav\',
    \'theme_location\' => \'primary\',
    \'depth\' => 2,
    \'container\' => \'div\',
    \'container_class\' => \'navbar-collapse collapse\',
    \'menu_class\' => \'nav navbar-nav navbar-right\',
    \'fallback_cb\' => \'wp_bootstrap_navwalker::fallback\',
    \'walker\' => new wp_bootstrap_navwalker()
)); ?>
然而,无论我做什么,页眉总是显示分配给页脚的其他菜单。我试着单独使用菜单和主题位置,更改名称,添加另一个位置,并将菜单分配给这个新位置,取消分配其他菜单和我能想到的任何东西,但都没有用。我所做的一切似乎都不管用,只是删除了另一个菜单,这当然不是我的主意,因为我想要两个菜单。

为了以防万一,页脚菜单的名称如下

<?php wp_nav_menu( array( \'theme_location\' => \'footer\' ) ); ?>
知道我做错了什么吗?

1 个回复
SO网友:Kevin John

我面对同样的问题,最终得到了答案:

对于functions.php:

register_nav_menu( \'primary\', __( \'Navigation Menu\', \'Removemymug_Theme\' ) );
register_nav_menu( \'second-menu\', __( \'Second Menu\', \'Removemymug_Theme\' ) );
对于辅助菜单(页脚):

wp_nav_menu( array(
    \'menu\'            => \'second-menu\',
    \'theme_location\'  => \'second-menu\',
    \'depth\'           => 2,
    \'container\'       => \'div\',
    \'container_class\' => \'navbar-collapse collapse\',
    \'menu_class\'      => \'nav navbar-nav navbar-right\',
    \'fallback_cb\'     => \'wp_bootstrap_navwalker::fallback\',
    \'walker\'          => new wp_bootstrap_navwalker()
) );
对于顶部导航:

wp_nav_menu( array(
    \'menu\'            => \'primary\',
    \'theme_location\'  => \'primary\',
    \'depth\'           => 2,
    \'container\'       => \'div\',
    \'container_class\' => \'navbar-collapse collapse\',
    \'menu_class\'      => \'nav navbar-nav navbar-right\',
    \'fallback_cb\'     => \'wp_bootstrap_navwalker::fallback\',
    \'walker\'          => new wp_bootstrap_navwalker()
) );

结束

相关推荐

Count > 1 Navigation Slider

我有一个帖子类型slider, 当您有多个帖子要显示导航时。我的代码:<?php $count_slider = wp_count_posts(\'slider\'); echo $count_slider->publish; ?> <?php if($count_slider > 1): ?> <div id=\"slideshowcontrol\" class=\"clearfi