如何混合两个菜单导航栏的HTML元素类型?
我正在用Bootstrap 4构建WordPress主题。
WordPress的菜单内容应来源于菜单选项,输出到Bootstrap 4导航栏。我正在使用this Bootstrap 4-specific wp_nav_menu
navwalker ...
require_once get_template_directory() . \'/inc/bs4navwalker.php\';
。。。要将导航文本链接的主菜单输出为无序列表,请执行以下操作
God intended...
<!-- Navbar https://getbootstrap.com/docs/4.1/components/navbar/ -->
<nav class="navbar navbar-expand-md navbar-light"><!-- collapse at stated breakpoint -->
<a class="navbar-brand" href="<?php echo esc_url( home_url( \'/\' ) ); ?>">
<img src="https://www.example.com/logo.gif" height="30" class="d-inline-block align-top mr-1">
<?php bloginfo( \'name\' ); ?>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs4navbar" aria-controls="bs4navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<?php
wp_nav_menu([ // bs4navwalker menu generator
\'menu\' => \'primary\', // name of wordpress menu
\'theme_location\' => \'primary\',
\'depth\' => 2,
// <nav>:
// \'container\' => \'false\',
\'container_id\' => \'bs4navbar\',
\'container_class\' => \'collapse navbar-collapse\',
// <ul>:
\'menu_id\' => false,
\'menu_class\' => \'navbar-nav ml-auto\',
// other:
\'fallback_cb\' => \'bs4navwalker::fallback\',
\'walker\' => new bs4navwalker()
]);
?>
<button class="btn btn-outline-primary mx-3" type="submit">Button</button>
<button class="btn btn-primary ml-3" type="submit">Sign up</button>
</nav>
这很好用。输出为。。。
<nav class="navbar navbar-expand-md navbar-light"><!-- collapse at stated breakpoint -->
<a class="navbar-brand" href="http://www.example.com/">
<img src="https://www.example.com/logo.gif" height="30" class="d-inline-block align-top mr-1">
Sandbox </a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs4navbar" aria-controls="bs4navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="bs4navbar" class="collapse navbar-collapse">
<ul id="menu-my-menu" class="navbar-nav ml-auto">
<li id="menu-item-3" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-3 nav-item mx-3 active"><a title="Home Page" href="http://sandbox.contexthq.com/" class="nav-link active" aria-expanded="false"><i class="icon-speedometer"></i>Home</a></li>
<li id="menu-item-4" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4 nav-item mx-3"><a title="Example Page" href="http://example.com/" class="nav-link" aria-expanded="false"><i class="ti-layout-grid2"></i>Trends</a></li>
<li id="menu-item-5" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5 nav-item mx-3"><a title="Custom Page" href="http://example.com/custom/" class="nav-link" aria-expanded="false"><i class="ti-palette"></i>Custom</a></li>
<li id="menu-item-14" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-14 nav-item mx-3"><a href="#" class="nav-link" aria-expanded="false">Strategy</a></li>
</ul>
</div>
<button class="btn btn-outline-primary mx-3" type="submit">Button</button>
<button class="btn btn-primary ml-3" type="submit">Sign up</button>
</nav>
但是,您将看到我手动插入两个
<button>
elements. 与硬编码不同,我希望这些代码是从WordPress菜单动态生成的,就像
primary
菜单
我制作了第二个WordPress菜单,buttons
. 这就是我崩溃的地方。。。
我可以插入第二个wp_nav_menu
需要buttons
, 就在第一个之后primary
...
<?php
wp_nav_menu([ // bs4navwalker menu generator
\'menu\' => \'buttons\', // name of wordpress menu
\'theme_location\' => \'buttons\',
\'depth\' => 2,
// <nav>:
// \'container\' => \'false\',
\'container_id\' => \'bs4navbar\',
\'container_class\' => \'collapse navbar-collapse\',
// <ul>:
\'menu_id\' => false,
\'menu_class\' => \'navbar-nav ml-auto\',
// other:
\'fallback_cb\' => \'bs4navwalker::fallback\',
\'walker\' => new bs4navwalker()
]);
?>
。。。菜单项将插入到正确的位置。
问题是,这些项目<li>
s在a内<ul>
, 就像primary
菜单
我想
bs4navwalker 设置为输出所有
wp_nav_menu
项目作为列表项目,或者WordPress正在这样做。
我怎样才能确保第二个菜单中的项目,buttons
, 使用不同的HTML结构获取输出,如<button>
而是元素?