所以,Custom Walkers是一個有點痛一起工作,直到你瞭解他們。
下面的自定義walker代碼應該爲你提供你所需要的。添加到您的主題的functions.php
文件:
class Custom_Button_Walker extends Walker_Nav_Menu {
// We only care about the "end level" part of the menu, where closing </ul> tags are generated
public function end_lvl(&$output, $depth = 0, $args = array()) {
// This is from WP core code
$indent = str_repeat("\t", $depth);
// This line ensures we only add it on the proper level
$button = (0 == $depth) ? "{$indent}<button type=\"button\">Click Me!</button>\n" : '';
// This line is modified to include the button markup
$output .= "{$indent}</ul>\n{$button}";
}
}
要使用自定義學步車,修改wp_nav_menu
調用就像這樣:
wp_nav_menu(array(
'theme_location' => 'main_menu',
'items_wrap' =>'%3$s',
'container' => FALSE,
'walker' => new Custom_Button_Walker()
));
你將有可能創建自己的[菜單沃克類](HTTPS: //www.smashingmagazine.com/2015/10/customize-tree-like-data-structures-wordpress-walker-class/)。你所要求的並不是一項簡單的任務。 –