improve custom menu hierarchy logic, See #11817

git-svn-id: http://svn.automattic.com/wordpress/trunk@13293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
wpmuguru 2010-02-22 17:27:34 +00:00
parent 803dd8b7c2
commit a2a3953308
1 changed files with 20 additions and 33 deletions

View File

@ -116,9 +116,10 @@ function wp_custom_navigation_output($args = array()) {
$queried_id = $wp_query->get_queried_object_id();
$parent_stack = array();
$current_parent = 0;
$parent_menu_order = array();
// 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);
$object_id = get_post_meta($menu_item->ID, 'object_id', true);
$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
?><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
@ -289,14 +265,25 @@ function wp_custom_navigation_output($args = array()) {
<?php
}
}
while ( !empty( $parent_stack ) ) { ?>
</li></ul>
<? array_shift( $parent_stack );
}
if ( !empty( $menu_items ) ) { ?>
// Indent children
$last_item = ( count( $menu_items ) == $menu_item->menu_order );
if ( $last_item || $current_parent != $menu_items[ $key + 1 ]->post_parent ) {
if ( $last_item || in_array( $menu_items[ $key + 1 ]->post_parent, $parent_stack ) ) { ?>
</li>
<?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
//RECURSIVE Sub Menu Items