这是我想要制作的真实图片。
<ul>
<li>
<ul>
<li> </li>
<li> </li>
###NOT HERE ###
</ul>
</Ii>
###I want to add some html here ###
</ul>
我尝试如下:
public function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && \'discard\' === $args->item_spacing ) {
$t = \'\';
$n = \'\';
} else {
$t = "\\t";
$n = "\\n";
}
$indent = str_repeat( $t, $depth );
$output .= "$indent".get_search_form(false)."</ul>{$n}";
}
但它在每个子菜单的末尾追加了搜索框(#####不在这里###部分)。如何实现所需的输出。有什么想法吗?
最合适的回答,由SO网友:Abdus Sattar Bhuiyan 整理而成
我应用此技巧过滤菜单:
add_filter(\'wp_nav_menu_items\',\'add_search_box_to_menu\', 10, 2);
function add_search_box_to_menu( $items, $args ) {
if( $args->theme_location == \'primary\' )
return $items."<li class=\'menu-header-search\'><form action=\'http://example.com/\' id=\'searchform\' method=\'get\'><input type=\'text\' name=\'s\' id=\'s\' placeholder=\'Search\'></form></li>";
return $items;
}