根据法典,你只需要使用depth
仅显示顶级页面的参数:
<?php wp_nav_menu( array( \'location\' => \'your_location\', \'depth\' => 1 ) ); ?>
有关更多参考,请参阅
this.
您还可以通过使用[wp_get_nav_menu_items][2]
然后使用自定义循环仅解析第一级和顶层页面。
编辑***我确实花了一些时间来开始一些帮助,不幸的是,我现在无法完成它,也许可以使它更优雅,但这可能是一个开始:
<?php
$menu_name = \'principal\';
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu_test = wp_get_nav_menu_object( $locations[ $menu_name ] );
// WE GET THE ITEMS IN menu_order
$menu_test_items = wp_get_nav_menu_items( $menu_test->term_id );
$top_items = array();
// LOOP THEM AND CREATE NESTED ARRAY LIKE THE MENU
foreach( $menu_test_items as $menu_test_item ) {
if ( $menu_test_item->menu_item_parent == 0 ) {
$top_items[$menu_test_item->ID][$menu_test_item->ID] = $menu_test_item;
} else {
$top_items[$menu_test_item->menu_item_parent][$menu_test_item->ID] = $menu_test_item;
}
}
// THEN WE COULD JUST LOOP IT x TIMES AND BREAK
foreach ( $top_items as $top_item ) {
// Npw you need to loop x times
// and display $top_item with another foreach
}
}
?>