您可以设置\'depth\'
参数到1
在您的wp_nav_menu()
调用以仅获取顶级项目,以及自定义菜单漫游器,如下所示:
return wp_nav_menu( array( \'menu\' => $name, \'menu_class\' => \'footer-menu\', \'echo\' => false, \'depth\' => 1, \'walker\' => new custom_footer_menu_walker ) );
将自定义菜单漫游器添加到您的函数中。php(12345是您主页的ID,应该排除在外):
class custom_footer_menu_walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
parent::start_el($item_html, $item, $depth, $args);
$exclude = array();
$exclude[] = 12345;
if ( ! in_array( $item->object_id, $exclude ) ) {
$output .= $item_html;
}
}
}