walk_tree broken, fixes #2608

git-svn-id: https://develop.svn.wordpress.org/trunk@3701 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2006-04-09 22:08:18 +00:00
parent 6768503353
commit 7caac09279
2 changed files with 12 additions and 11 deletions

View File

@ -717,7 +717,7 @@ function &get_page(&$page, $output = OBJECT) {
function walk_tree($tree_type, $elements, $to_depth, $start_element_callback, $end_element_callback = '', $start_level_callback = '', $end_level_callback = '') {
$args = array_slice(func_get_args(), 7);
$parents = array();
$depth = 0;
$depth = 1;
$previous_element = '';
$output = '';
@ -758,24 +758,25 @@ function walk_tree($tree_type, $elements, $to_depth, $start_element_callback, $e
// Walk the tree.
if ( !empty($previous_element) && ($element->$parent_field == $previous_element->$id_field) ) {
// Previous element is my parent. Descend a level.
$depth++; //always do this so when we start the element further down, we know where we are
array_unshift($parents, $previous_element);
$depth++;
if ( !$to_depth || ($depth < $to_depth) )
if ( !$to_depth || ($depth < $to_depth) ) { //only descend if we're below $to_depth
if ( !empty($start_level_callback) ) {
$cb_args = array_merge( array($output, $depth), $args);
$output = call_user_func_array($start_level_callback, $cb_args);
}
} else if ( $depth && ($element->$parent_field == $previous_element->$parent_field) ) {
// On the same level as previous element.
if ( !$to_depth || ($depth < $to_depth) ) {
}
} else if ( $element->$parent_field == $previous_element->$parent_field ) {
// On the same level as previous element, so close the previous
if ( !$to_depth || ($depth <= $to_depth) ) {
if ( !empty($end_element_callback) ) {
$cb_args = array_merge( array($output, $previous_element, $depth), $args);
$output = call_user_func_array($end_element_callback, $cb_args);
}
}
} else if ( $depth ) {
} else if ( $depth > 1 ) {
// Ascend one or more levels.
if ( !$to_depth || ($depth < $to_depth) ) {
if ( !$to_depth || ($depth <= $to_depth) ) {
if ( !empty($end_element_callback) ) {
$cb_args = array_merge( array($output, $previous_element, $depth), $args);
$output = call_user_func_array($end_element_callback, $cb_args);
@ -800,7 +801,7 @@ function walk_tree($tree_type, $elements, $to_depth, $start_element_callback, $e
}
} else if ( !empty($previous_element) ) {
// Close off previous element.
if ( !$to_depth || ($depth < $to_depth) ) {
if ( !$to_depth || ($depth <= $to_depth) ) {
if ( !empty($end_element_callback) ) {
$cb_args = array_merge( array($output, $previous_element, $depth), $args);
$output = call_user_func_array($end_element_callback, $cb_args);
@ -809,7 +810,7 @@ function walk_tree($tree_type, $elements, $to_depth, $start_element_callback, $e
}
// Start the element.
if ( !$to_depth || ($depth < $to_depth) ) {
if ( !$to_depth || ($depth <= $to_depth) ) {
if ( !empty($start_element_callback) && ($element->$id_field != 0) ) {
$cb_args = array_merge( array($output, $element, $depth), $args);
$output = call_user_func_array($start_element_callback, $cb_args);

View File

@ -428,7 +428,7 @@ function wp_list_pages($args = '') {
global $wp_query;
$current_page = $wp_query->get_queried_object_id();
$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']);
$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']);
if ( $r['title_li'] )
$output .= '</ul></li>';