我正在手动创建菜单,并尝试包含搜索表单。
这摘自Wordpress文档“构建简单菜单列表”,网址为http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items.
我添加了一个额外的<;li>;元素,并添加了搜索表单。
// Get the nav menu based on $menu_name (same as \'theme_location\' or \'menu\' arg to wp_nav_menu)
// This code based on wp_nav_menu\'s code to get Menu ID from menu slug
$menu_name = \'main-menu\';
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list = \'<ul id="menu-\' . $menu_name . \'">\';
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= \'<li><a href="\' . $url . \'">\' . $title . \'</a></li>\';
}
$menu_list .= \'<li>\' . get_search_form(false) . \'</li>\';
$menu_list .= \'</ul>\';
} else {
$menu_list = \'<ul><li>No Menu</li></ul>\';
}
echo $menu_list;
问题出在输出中。
<;div class=“mainnav”role=“导航”>;
<form role="search" method="get" id="searchform" action="/">
<input type="text" value="" name="s" id="s" size="40" placeholder="Search" alt="Site Search">
<input type="submit" id="searchsubmit" value="Search">
</form>
<ul id="menu-main-menu">
<li><a href="#">Home</a></li>
<li><a href="#">Sample Page</a></li>
<li></li>
</ul>
</div>;
有人能告诉我为什么即使我指定echo=false,搜索仍在菜单之前打印?