Make WordPress Core

Changeset 13293


Ignore:
Timestamp:
02/22/2010 05:27:34 PM (17 years ago)
Author:
wpmuguru
Message:

improve custom menu hierarchy logic, See #11817

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/custom-navigation.php

    r13287 r13293  
    117117
    118118                $parent_stack = array();
     119                $current_parent = 0;
    119120                $parent_menu_order = array();
    120121            // Display Loop
    121                 foreach ( $menu_items as $menu_item ) {
     122                foreach ( $menu_items as $key => $menu_item ) {
    122123                        $menu_type = get_post_meta($menu_item->ID, 'menu_type', true);
    123124                        $object_id = get_post_meta($menu_item->ID, 'object_id', true);
    … …  
    200201                        }
    201202*/
    202                         // Indent children
    203                         if ( empty( $parent_stack ) ) {
    204                                 array_unshift( $parent_stack, $menu_item->ID );
    205                         } elseif ( $menu_item->post_parent > 0 ) {
    206                                 if ( $menu_item->post_parent == $parent_stack[0] ) { ?>
    207                         <ul>
    208 <?php                                   array_unshift( $parent_stack, $menu_item->ID );
    209                                 } elseif ( count( $parent_stack ) > 1 && $menu_item->post_parent == $parent_stack[1] ) { ?>
    210                         </li>
    211 <?php                                   $parent_stack[0] = $menu_item->ID;
    212                                 } elseif ( in_array( $menu_item->post_parent, $parent_stack ) ) {
    213                                         while ( !empty( $parent_stack ) && $menu_item->post_parent != $parent_stack[0] ) { ?>
    214                         </li></ul>
    215 <?                                              array_shift( $parent_stack );
    216                                         }
    217                                 }
    218                         } else {
    219                                 while ( count( $parent_stack ) > 1 ) { ?>
    220                         </li></ul>
    221 <?                                      array_shift( $parent_stack );
    222                                 } ?>
    223                         </li>
    224 <?php                           $parent_stack[0] = $menu_item->ID;
    225                         }
    226 
    227203                        // List Items
    228204                        ?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $li_class; ?>><?php
    … …  
    290266                                                <?php
    291267                                        }
    292                 }
    293                 while ( !empty( $parent_stack ) ) { ?>
    294                         </li></ul>
    295 <?                      array_shift( $parent_stack );
    296                 }
    297                 if ( !empty( $menu_items ) ) { ?>
     268                        // Indent children
     269                        $last_item = ( count( $menu_items ) == $menu_item->menu_order );
     270                        if ( $last_item || $current_parent != $menu_items[ $key + 1 ]->post_parent ) {
     271                                if ( $last_item || in_array( $menu_items[ $key + 1 ]->post_parent, $parent_stack ) ) { ?>
    298272                </li>
    299 <?php           }
     273<?php                                   while ( !empty( $parent_stack ) && ($last_item || $menu_items[ $key + 1 ]->post_parent != $current_parent ) ) { ?>
     274                        </ul>
     275                </li>
     276<?                                              $current_parent = array_pop( $parent_stack );
     277                                        } ?>
     278<?php                           } else {
     279                                        array_push( $parent_stack, $current_parent );
     280                                        $current_parent = $menu_item->ID; ?>
     281                        <ul>
     282<?php                           }
     283                        } else { ?>
     284                </li>
     285<?php                   }
     286        }               
    300287}
    301288//@todo: implement menu heirarchy
Note: See TracChangeset for help on using the changeset viewer.