Make WordPress Core

Ticket #2608: 2608.diff

File 2608.diff, 3.7 KB (added by davidhouse, 21 years ago)
  • wp-includes/template-functions-post.php

     
    427427
    428428                global $wp_query;
    429429                $current_page = $wp_query->get_queried_object_id();
    430                 $output .= walk_page_tree($pages, $depth, '_page_list_element_start', '_page_list_element_end', '_page_list_level_start', '_page_list_level_end', $current_page, $r['show_date'], $r['date_format']);
     430                $output .= walk_page_tree($pages, $r['depth'], '_page_list_element_start', '_page_list_element_end', '_page_list_level_start', '_page_list_level_end', $current_page, $r['show_date'], $r['date_format']);
    431431
    432432                if ( $r['title_li'] )
    433433                        $output .= '</ul></li>';
  • wp-includes/functions.php

     
    708708function walk_tree($tree_type, $elements, $to_depth, $start_element_callback, $end_element_callback = '', $start_level_callback = '', $end_level_callback = '') {
    709709        $args = array_slice(func_get_args(), 7);
    710710        $parents = array();
    711         $depth = 0;
     711        $depth = 1; //1 is top level
    712712        $previous_element = '';
    713713        $output = '';
    714714
    … …  
    749749                // Walk the tree.
    750750                if ( !empty($previous_element) && ($element->$parent_field == $previous_element->$id_field) ) {
    751751                        // Previous element is my parent. Descend a level.
     752                        $depth++; //always do this so when we start the element further down, we know where we are
    752753                        array_unshift($parents, $previous_element);
    753                         $depth++;
    754                         if ( !$to_depth || ($depth < $to_depth) )
     754                        if ( !$to_depth || ($depth < $to_depth) ) { //only descend if we're below $to_depth
    755755                                if ( !empty($start_level_callback) ) {
    756756                                        $cb_args = array_merge( array($output, $depth), $args);
    757757                                        $output = call_user_func_array($start_level_callback, $cb_args);
    758758                                }
    759                 } else if ( $depth && ($element->$parent_field == $previous_element->$parent_field) ) {
    760                         // On the same level as previous element.
    761                         if ( !$to_depth || ($depth < $to_depth) ) {
     759                        }
     760                } else if ( $element->$parent_field == $previous_element->$parent_field ) {
     761                        // On the same level as previous element, so close the previous
     762                        if ( !$to_depth || ($depth <= $to_depth) ) {
    762763                                if ( !empty($end_element_callback) ) {
    763764                                        $cb_args = array_merge( array($output, $previous_element, $depth), $args);
    764765                                        $output = call_user_func_array($end_element_callback, $cb_args);
    765766                                }
    766767                        }
    767                 } else if ( $depth ) {
     768                } else if ( $depth > 1 ) {
    768769                        // Ascend one or more levels.
    769                         if ( !$to_depth || ($depth < $to_depth) ) {
     770                        if ( !$to_depth || ($depth <= $to_depth) ) {
    770771                                if ( !empty($end_element_callback) ) {
    771772                                        $cb_args = array_merge( array($output, $previous_element, $depth), $args);
    772773                                        $output = call_user_func_array($end_element_callback, $cb_args);
    … …  
    791792                        }
    792793                } else if ( !empty($previous_element) ) {
    793794                        // Close off previous element.
    794                         if ( !$to_depth || ($depth < $to_depth) ) {
     795                        if ( !$to_depth || ($depth <= $to_depth) ) {
    795796                                if ( !empty($end_element_callback) ) {
    796797                                        $cb_args = array_merge( array($output, $previous_element, $depth), $args);
    797798                                        $output = call_user_func_array($end_element_callback, $cb_args);
    … …  
    800801                }
    801802
    802803                // Start the element.
    803                 if ( !$to_depth || ($depth < $to_depth) ) {
     804                if ( !$to_depth || ($depth <= $to_depth) ) {
    804805                        if ( !empty($start_element_callback) && ($element->$id_field != 0) ) {
    805806                                $cb_args = array_merge( array($output, $element, $depth), $args);
    806807                                $output = call_user_func_array($start_element_callback, $cb_args);