improve custom menu hierarchy logic, See #11817
git-svn-id: https://develop.svn.wordpress.org/trunk@13293 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ec95afd3ca
commit
117a68163d
|
@ -116,9 +116,10 @@ function wp_custom_navigation_output($args = array()) {
|
||||||
$queried_id = $wp_query->get_queried_object_id();
|
$queried_id = $wp_query->get_queried_object_id();
|
||||||
|
|
||||||
$parent_stack = array();
|
$parent_stack = array();
|
||||||
|
$current_parent = 0;
|
||||||
$parent_menu_order = array();
|
$parent_menu_order = array();
|
||||||
// Display Loop
|
// Display Loop
|
||||||
foreach ( $menu_items as $menu_item ) {
|
foreach ( $menu_items as $key => $menu_item ) {
|
||||||
$menu_type = get_post_meta($menu_item->ID, 'menu_type', true);
|
$menu_type = get_post_meta($menu_item->ID, 'menu_type', true);
|
||||||
$object_id = get_post_meta($menu_item->ID, 'object_id', true);
|
$object_id = get_post_meta($menu_item->ID, 'object_id', true);
|
||||||
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
|
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
|
||||||
|
@ -199,31 +200,6 @@ function wp_custom_navigation_output($args = array()) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// Indent children
|
|
||||||
if ( empty( $parent_stack ) ) {
|
|
||||||
array_unshift( $parent_stack, $menu_item->ID );
|
|
||||||
} elseif ( $menu_item->post_parent > 0 ) {
|
|
||||||
if ( $menu_item->post_parent == $parent_stack[0] ) { ?>
|
|
||||||
<ul>
|
|
||||||
<?php array_unshift( $parent_stack, $menu_item->ID );
|
|
||||||
} elseif ( count( $parent_stack ) > 1 && $menu_item->post_parent == $parent_stack[1] ) { ?>
|
|
||||||
</li>
|
|
||||||
<?php $parent_stack[0] = $menu_item->ID;
|
|
||||||
} elseif ( in_array( $menu_item->post_parent, $parent_stack ) ) {
|
|
||||||
while ( !empty( $parent_stack ) && $menu_item->post_parent != $parent_stack[0] ) { ?>
|
|
||||||
</li></ul>
|
|
||||||
<? array_shift( $parent_stack );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while ( count( $parent_stack ) > 1 ) { ?>
|
|
||||||
</li></ul>
|
|
||||||
<? array_shift( $parent_stack );
|
|
||||||
} ?>
|
|
||||||
</li>
|
|
||||||
<?php $parent_stack[0] = $menu_item->ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
// List Items
|
// List Items
|
||||||
?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $li_class; ?>><?php
|
?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $li_class; ?>><?php
|
||||||
//@todo: update front end to use post data
|
//@todo: update front end to use post data
|
||||||
|
@ -289,14 +265,25 @@ function wp_custom_navigation_output($args = array()) {
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
// Indent children
|
||||||
while ( !empty( $parent_stack ) ) { ?>
|
$last_item = ( count( $menu_items ) == $menu_item->menu_order );
|
||||||
</li></ul>
|
if ( $last_item || $current_parent != $menu_items[ $key + 1 ]->post_parent ) {
|
||||||
<? array_shift( $parent_stack );
|
if ( $last_item || in_array( $menu_items[ $key + 1 ]->post_parent, $parent_stack ) ) { ?>
|
||||||
}
|
|
||||||
if ( !empty( $menu_items ) ) { ?>
|
|
||||||
</li>
|
</li>
|
||||||
<?php }
|
<?php while ( !empty( $parent_stack ) && ($last_item || $menu_items[ $key + 1 ]->post_parent != $current_parent ) ) { ?>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<? $current_parent = array_pop( $parent_stack );
|
||||||
|
} ?>
|
||||||
|
<?php } else {
|
||||||
|
array_push( $parent_stack, $current_parent );
|
||||||
|
$current_parent = $menu_item->ID; ?>
|
||||||
|
<ul>
|
||||||
|
<?php }
|
||||||
|
} else { ?>
|
||||||
|
</li>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//@todo: implement menu heirarchy
|
//@todo: implement menu heirarchy
|
||||||
//RECURSIVE Sub Menu Items
|
//RECURSIVE Sub Menu Items
|
||||||
|
|
Loading…
Reference in New Issue