我正在从头开始创建一个引导wordpress主题,我想使用wordpress nav walker类创建一个nav菜单,我遵循了上的文档GitHub 为了安装它,我在我的wordpress主题中添加了一个主菜单,我选择了菜单位置,但导航栏不会显示,我所拥有的只是位于中心的导航栏品牌。 我的标题。php代码:
<div class="blog-masthead">
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php echo home_url(); ?>">
<?php bloginfo(\'name\'); ?>
</a>
</div>
<?php
wp_nav_menu( array(
\'menu\' => \'primary\',
\'theme_location\' => \'primary\',
\'depth\' => 2,
\'container\' => \'div\',
\'container_class\' => \'collapse navbar-collapse\',
\'container_id\' => \'bs-example-navbar-collapse-1\',
\'menu_class\' => \'nav navbar-nav\',
\'fallback_cb\' => \'WP_Bootstrap_Navwalker::fallback\',
\'walker\' => new WP_Bootstrap_Navwalker())
);
?>
</div>
</nav>
</div>
</div>
功能。php
<?php
require_once(\'wp-bootstrap-navwalker.php\');
function wpb_theme_setup(){
register_nav_menus( array(
\'primary\' => __( \'Primary Menu\', \'wpbootstrap\' ),
) );
}
add_action(\'after_setup_theme\', \'wpb_theme_setup\');
有人能帮我解决这个问题吗?
SO网友:sakarya
我是这样用的。我从未遇到过任何问题。
引导程序3。带有wordpress下拉菜单的x导航。
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand visible-xs" href="#">MENU</a>
</div>
<div class="collapse navbar-collapse" id="bs-navbar-collapse">
<?php
wp_nav_menu( array(
\'theme_location\' => \'primary\',
\'depth\' => 2,
\'container\' => \'\',
\'menu_class\' => \'nav navbar-nav\',
\'fallback_cb\' => \'wp_bootstrap_navwalker::fallback\',
\'walker\' => new wp_bootstrap_navwalker())
);
?>
<ul class="nav navbar-nav navbar-right">
<?php if ( is_user_logged_in() ) { ?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-user-plus" aria-hidden="true"></i> HESABIM <span class="caret"></span></a>
<ul class="dropdown-menu">
<?php foreach ( wc_get_account_menu_items() as $endpoint => $label ) : ?>
<li><a href="<?php echo esc_url( wc_get_account_endpoint_url( $endpoint ) ); ?>"><?php echo esc_html( $label ); ?></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php } else { ?>
<li><a href="<?php echo get_permalink( get_option(\'woocommerce_myaccount_page_id\') ); ?>" title="Üye Ol / Giriş Yap">Üye Ol / Giriş Yap</a></li>
<?php } ?>
</ul>
</div>
仅导航;
<div class="collapse navbar-collapse" id="bs-navbar-collapse">
<?php
wp_nav_menu( array(
\'theme_location\' => \'primary\',
\'depth\' => 2,
\'container\' => \'\',
\'menu_class\' => \'nav navbar-nav\',
\'fallback_cb\' => \'wp_bootstrap_navwalker::fallback\',
\'walker\' => new wp_bootstrap_navwalker())
);
?>
</div>