我是wordpress主题的新手。我正在尝试显示导航菜单
<div class="nav-collapse" id="collapse">
<ul class="nav nav-pills">
<li ><a href="index.php">Home</a></li>
<li ><a href="facilities.php">Facilities</a></li>
<li ><a href="tariff.php">Rooms & Tariff</a></li>
<li ><a href="bookings.php">Booking</a></li>
<li ><a href="contact.php">Contact</a></li>
</ul>
</div><!-- /.nav-collapse -->
为此,我在functions.php
function heritage_register_theme_menu() {
register_nav_menu( 'primary', 'Main Navigation Menu' );
}
add_action( 'init', 'heritage_register_theme_menu' );
并添加了header.php
中的菜单:
$defaults = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => 'nav-collapse',
'container_id' => '',
'menu_class' => 'nav nav-pills',
'menu_id' => '',
'echo' => true,
//'fallback_cb' => false,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
但在我选中的源代码中,它会将HTML
显示为:
<div class="nav nav-pills">
<ul>
<li class="page_item page-item-9"><a href="http://localhost/projects/wordpress/?page_id=9">PHP Developer</a></li>
<li class="page_item page-item-2"><a href="http://localhost/projects/wordpress/?page_id=2">Sample Page</a></li>
</ul>
</div>
所以我想知道:
nav nav-pills
添加到ul
而不是包装div?答案 0 :(得分:1)
您已在functions.php中注册了导航菜单,但在使用wp_nav_menu
时您尚未使用该菜单。
变化:
'theme_location' => '',
致:
'theme_location' => 'primary',
然后你需要去外观 - &gt;如果您还没有菜单,请设置并设置菜单。