我知道这个问题已经被问了好几次了,但我似乎仍然找不到解决我的确切问题的方法。
这是我的菜单的非wordpress版本:
<div class="nav-container">
<div>
<div class="bar bar--sm visible-xs">
<div class="container">
<div class="row">
<div class="col-3 col-md-2">
<a href="index.html"> <img class="logo logo-dark" alt="logo" src="img/logo-dark.png"> <img class="logo logo-light" alt="logo" src="img/logo-light.png"> </a>
</div>
<div class="col-9 col-md-10 text-right">
<a href="#" class="hamburger-toggle" data-toggle-class="#menu1;hidden-xs hidden-sm"> <i class="icon icon--sm stack-interface stack-menu"></i> </a>
</div>
</div>
</div>
</div>
<nav id="menu1" class="bar bar-1 hidden-xs">
<div class="container">
<div class="row">
<div class="col-lg-1 col-md-2 hidden-xs">
<div class="bar__module">
<a href="index.html"> <img class="logo logo-dark" alt="logo" src="img/logo-dark.png"> <img class="logo logo-light" alt="logo" src="img/logo-light.png"> </a>
</div>
</div>
<div class="col-lg-11 col-md-12 text-right text-left-xs text-left-sm">
<div class="bar__module">
<ul class="menu-horizontal text-left">
<li> <a href="#">
Single Link
</a> </li>
<li class="dropdown"> <span class="dropdown__trigger">
Dropdown Slim
</span>
<div class="dropdown__container">
<div class="container">
<div class="row">
<div class="dropdown__content col-lg-2">
<ul class="menu-vertical">
<li> <a href="#">Single Link</a> </li>
</ul>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
</div>
</div>
我确实发现,我似乎应该使用我加载的引导导航助行器:
https://github.com/wp-bootstrap/wp-bootstrap-navwalker
下面是我如何修改导航以使其在Wordpress中工作的:
<div class="nav-container">
<div>
<div class="bar bar--sm visible-xs">
<div class="container">
<div class="row">
<div class="col-3 col-md-2">
<a href="index.html"> <img class="logo logo-dark" alt="logo" src="img/logo-dark.png"> <img class="logo logo-light" alt="logo" src="img/logo-light.png"> </a>
</div>
<div class="col-9 col-md-10 text-right">
<a href="#" class="hamburger-toggle" data-toggle-class="#menu1;hidden-xs hidden-sm"> <i class="icon icon--sm stack-interface stack-menu"></i> </a>
</div>
</div>
</div>
</div>
<nav id="menu1" class="bar bar-1 hidden-xs">
<div class="container">
<div class="row">
<div class="col-lg-1 col-md-2 hidden-xs">
<div class="bar__module">
<a href="index.html"> <img class="logo logo-dark" alt="logo" src="img/logo-dark.png"> <img class="logo logo-light" alt="logo" src="img/logo-light.png"> </a>
</div>
</div>
<div class="col-lg-11 col-md-12 text-right text-left-xs text-left-sm">
<div class="bar__module">
<?php
$args = [
\'theme_location\' => \'main-menu\',
\'depth\' => 2,
\'menu_class\' => \'menu-horizontal text-left\',
\'walker\' => new WP_Bootstrap_Navwalker()
];
wp_nav_menu( $args );
?>
</div>
</div>
</div>
</div>
</nav>
</div>
</div>
这将正确显示非下拉菜单,但实际的下拉列表只应在激活后显示,以可怕的蓝色文本显示,并且根本没有正确的样式。
最合适的回答,由SO网友:Sally CJ 整理而成
尝试this walker.
示例用法:
wp_nav_menu( [
\'menu_class\' => \'menu-horizontal text-left\',
\'container\' => \'\',
\'depth\' => 2,
\'theme_location\' => \'main-menu\',
// You should have loaded the class-my-bs-walker-nav-menu.php file from
// within the theme\'s functions.php file.
\'walker\' => new My_BS_Walker_Nav_Menu,
] );
walker不是任何引导菜单的“全局”walker;相反,它只针对您在问题中提供的菜单结构。