我找到了这个http://wpsmith.net/2011/how-to-get-all-the-children-of-a-specific-nav-menu-item/
并且写了这个代码,所以它被修复了!
函数get\\u nav\\u menu\\u item\\u children($menu,$depth=true){
$post_id = $post_id ? : get_the_ID();
$menu_items = wp_get_nav_menu_items($menu);
$parent_item_id = wp_filter_object_list($menu_items, array(\'object_id\' => $post_id), \'and\', \'menu_item_parent\');
if (!empty($parent_item_id)) {
$parent_item_id = array_shift($parent_item_id);
$parent_post_id = wp_filter_object_list($menu_items, array(\'ID\' => $parent_item_id), \'and\', \'object_id\');
if (!empty($parent_post_id)) {
$parent_post_id = array_shift($parent_post_id);
$parent_id= get_post($parent_post_id)->ID;
}
}
$nav_menu_item_list = array();
foreach ((array) $menu_items as $nav_menu_item) {
if ($nav_menu_item->post_parent == $parent_id) {
$nav_menu_item_list[] = $nav_menu_item;
}
}
return $nav_menu_item_list;
}
Usage
$menuSide=get_nav_menu_item_children(\'Main menu\');
foreach ($menuSide as $link):
$active=\'\';
if(intval($post->ID)===intval($link->object_id)){
$active=\' current_page_item \';
}
echo \' <li class="\'.$active.\'"><a href="\'.$link->url.\'">\' . $link->title . \'</a></li>\';
endforeach;