我使用的是二十一主题,下面是它用来注册和显示菜单的代码。
In functions.php:
function twentytwelve_setup() {
...
// This theme uses wp_nav_menu() in one location.
register_nav_menu( \'primary\', __( \'Primary Menu\', \'twentytwelve\' ) );
...
}
add_action( \'after_setup_theme\', \'twentytwelve_setup\' );
In header.php:
<nav class="site-navigation main-navigation" role="navigation">
<?php wp_nav_menu( array( \'theme_location\' => \'primary\' ) ); ?>
</nav>
输出代码如下所示:
<nav class="site-navigation main-navigation" role="navigation">
<div class="menu-main-menu-container">
<ul id="menu-main-menu" class="menu">
<li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-9">
<a href="http://aahank.com/">Home</a>
</li>
<li id="menu-item-12" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-12">
<a href="http://example.com/">About</a>
</li>
</ul>
</div>
</nav>
但我想修改输出,以便搜索框可以作为如下菜单项集成到导航菜单中:
<nav class="site-navigation main-navigation" role="navigation">
<div class="menu-main-menu-container">
<ul id="menu-main-menu" class="menu">
<li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-9">
<a href="http://aahank.com/">Home</a>
</li>
<li id="menu-item-12" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-12">
<a href="http://example.com/">About</a>
</li>
<li id="menu-item-13" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-13">
<!-- Search box inside nav as a menu item -->
<form method="get" id="searchform" action="/">
<label for="s" class="assistive-text">Search</label>
<input type="text" class="field" name="s" id="s" placeholder="Search" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
</form>
</li>
</ul>
</div>
</nav>
我该怎么做呢?我需要一两个代码支持的指针。也欢迎用汤匙喂食P