Two menus show up

时间:2015-01-26 作者:Laniakea

如果我将“echo”参数值设置为“true”:

<?php if( has_nav_menu( \'primary-menu\' ) ) {
                    wp_nav_menu( $menuParameters = array( 
                        \'theme_location\'  => \'primary-menu\',
                        \'container\'       => \'\', 
                        \'container_class\' => false,
                        \'container_id\'    => false,
                        \'menu\'            => \'Primary\',
                        \'menu_id\'         => \'test\',
                        \'menu_class\'      => \'nav navbar-nav navbar-right\',
                        \'echo\'            => true,
                        \'fallback_cb\'     => \'wp_page_menu\',
                        \'before\'          => \'\',
                        \'after\'           => \'\',
                        \'link_before\'     => \'\',
                        \'link_after\'      => \'\',
                        \'items_wrap\'      => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
                        \'depth\'           => 0,
                        \'walker\'          => \'\'

                        ) ); 

                    wp_nav_menu (array(\'theme_location\' => \'primary-menu\'));

                    } ?>
我得到以下输出:

<ul id="test" class="nav navbar-nav navbar-right">
 <li class="current-menu-item"><a href="http://localhost/test/">Home</a></li>
 <li><a href="http://localhost/test/contact/">Contact</a></li>
</ul>
<ul id="menu-primary" class="menu">
 <li class="current-menu-item"><a href="http://localhost/test/">Home</a></li>
 <li><a href="http://localhost/test/contact/">Contact</a></li>
</ul>
第一个是期望的结果,最后一个是WP默认输出,这是一个难题。有没有办法通过改变我的数组来摆脱它?

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

您有两次调用wp\\u nav\\u菜单功能

<?php if( has_nav_menu( \'primary-menu\' ) ) {
    wp_nav_menu( $menuParameters = array( 
        \'theme_location\'  => \'primary-menu\',
        \'container\'       => \'\', 
        \'container_class\' => false,
        \'container_id\'    => false,
        \'menu\'            => \'Primary\',
        \'menu_id\'         => \'test\',
        \'menu_class\'      => \'nav navbar-nav navbar-right\',
        \'echo\'            => true,
        \'fallback_cb\'     => \'wp_page_menu\',
        \'before\'          => \'\',
        \'after\'           => \'\',
        \'link_before\'     => \'\',
        \'link_after\'      => \'\',
        \'items_wrap\'      => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
        \'depth\'           => 0,
        \'walker\'          => \'\'

        ) ); 

    // Following is outputing second menu html
    //wp_nav_menu (array(\'theme_location\' => \'primary-menu\'));

} ?>

结束

相关推荐

直接从post.php编辑帖子元吗?

有没有人知道一种简单的方法可以一次编辑一篇文章的所有metapost.php &action=edit 页因为一些元被放在那里update_post_meta() 如果有一种方法可以从帖子的编辑页面编辑任何元值,那真的很有帮助吗?一直在寻找任何东西,代码/插件,但看不到有太多提及,但认为这一定是一个很常见的问题?我附上了一张通过浏览器检查器编辑的元检查器中我想象的解决方案的图片,以防不清楚我在问什么