这将添加类sub-menu-0
, sub-menu-1
等等,这取决于它们的深度。
//This will go in functions.php file
class wpse61220_submenu_class extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\\t", $depth);
$output .= "\\n$indent<ul class=\\"sub-menu-".$depth."\\">\\n";
}
}
// Usage -
// wp_nav_menu( array(\'walker\' => new wpse61220_submenu_class() ) );
Reference - 作用wp_nav_menu()