From d34428341a4e2174af9fabe871fd11a13e35e9fe Mon Sep 17 00:00:00 2001
From: wpmuguru <wpmuguru@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
Date: Mon, 22 Feb 2010 02:01:44 +0000
Subject: [PATCH] output correct parent id, visual hierarchy in admin, See
 #11817

git-svn-id: http://svn.automattic.com/wordpress/trunk@13287 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 wp-includes/custom-navigation.php | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/wp-includes/custom-navigation.php b/wp-includes/custom-navigation.php
index 11b789acf9..354d95fd95 100644
--- a/wp-includes/custom-navigation.php
+++ b/wp-includes/custom-navigation.php
@@ -116,11 +116,17 @@ function wp_custom_navigation_output($args = array()) {
 			$queried_id = $wp_query->get_queried_object_id();
 
 		$parent_stack = array();
+		$parent_menu_order = array();
 	    // Display Loop
 		foreach ( $menu_items as $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;
+			if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) )
+				$parent_item = $parent_menu_order[ $menu_item->post_parent ];
+			else
+				$parent_item = 0;
+
 			switch ( $menu_type ) {
 				// Page Menu Item
 				case 'page':
@@ -209,7 +215,11 @@ function wp_custom_navigation_output($args = array()) {
 <?						array_shift( $parent_stack );
 					}
 				}
-			} else { ?>
+			} else {
+				while ( count( $parent_stack ) > 1 ) { ?>
+			</li></ul>
+<?					array_shift( $parent_stack );
+				} ?>
 			</li>
 <?php				$parent_stack[0] = $menu_item->ID;
 			}
@@ -267,7 +277,7 @@ function wp_custom_navigation_output($args = array()) {
 						<a><span class=""></span></a>
 						<input type="hidden" name="dbid<?php echo $menu_item->menu_order; ?>" id="dbid<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->ID; ?>" />
 						<input type="hidden" name="postmenu<?php echo $menu_item->menu_order; ?>" id="postmenu<?php echo $menu_item->menu_order; ?>" value="<?php echo $id; ?>" />
-						<input type="hidden" name="parent<?php echo $menu_item->menu_order; ?>" id="parent<?php echo $menu_item->menu_order; ?>" value="<?php echo $menu_item->post_parent; ?>" />
+						<input type="hidden" name="parent<?php echo $menu_item->menu_order; ?>" id="parent<?php echo $menu_item->menu_order; ?>" value="<?php echo $parent_item; ?>" />
 						<input type="hidden" name="title<?php echo $menu_item->menu_order; ?>" id="title<?php echo $menu_item->menu_order; ?>" value="<?php echo $title; ?>" />
 						<input type="hidden" name="linkurl<?php echo $menu_item->menu_order; ?>" id="linkurl<?php echo $menu_item->menu_order; ?>" value="<?php echo $link; ?>" />
 						<input type="hidden" name="description<?php echo $menu_item->menu_order; ?>" id="description<?php echo $menu_item->menu_order; ?>" value="<?php echo $description; ?>" />