Use a custom walker, 扩展方法start_lvl()
和end_lvl
.
未测试的示例代码:
class WPSE_78121_Sublevel_Walker extends Walker_Nav_Menu
{
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\\t", $depth);
$output .= "\\n$indent<div class=\'sub-menu-wrap\'><ul class=\'sub-menu\'>\\n";
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\\t", $depth);
$output .= "$indent</ul></div>\\n";
}
}
主题中的用法:
wp_nav_menu(
array (
\'theme_location\' => \'your-theme-location-EDIT-THIS\',
\'walker\' => new WPSE_78121_Sublevel_Walker
)
);