我想在侧边栏菜单中使用“depth”只显示第一个子页面,我想知道我应该在代码中的什么地方插入depth?我想只显示第一个子页面,而不是所有子页面。我已尝试在此if条件下插入“depth”
if ( $item->current_item_ancestor && $item->menu_item_parent == \'0\' )
{
$last_parent = $item,
\'depth\' => 1
}
/* ------------------------------------------------------------------- */
function myproject_nav_menu_objects_start_in( $sorted_menu_items, $args )
{
switch ( $args->menu_id )
{
case \'sidebar-menu\' :
$current = false;
$last_parent = false;
$menu = array();
foreach( $sorted_menu_items as $item )
{
if ( $item->current_item_ancestor && $item->menu_item_parent == \'0\' )
$last_parent = $item;
if ( $item->current )
$current = $item;
}
if ( $current )
{
$keys = array();
$last_parent = ( ! $last_parent ) ? $current : $last_parent;
$children = _myproject_submenu_get_children_ids( $last_parent->ID, $sorted_menu_items );
foreach ( $sorted_menu_items as $key => $item )
{
if ( ! in_array( $item->ID, $children ) )
unset( $sorted_menu_items[$key] );
}
}
else
{
$sorted_menu_items = array();
}
break;
}
return $sorted_menu_items;
}
add_filter( \'wp_nav_menu_objects\', \'myproject_nav_menu_objects_start_in\', 10, 2 );