Changeset 6388

Show
Ignore:
Timestamp:
12/16/07 20:31:44 (9 months ago)
Author:
ryan
Message:

Fix depth = 1 page traversal. Props hailin. fixes #5469

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/classes.php

    r6384 r6388  
    409409        if ( !$element) 
    410410            return $output;  
    411          
     411            
    412412        if ( $max_depth != 0 ) { 
    413413            if ($depth >= $max_depth) 
    414414                return $output;  
    415415        } 
    416      
     416        
    417417        $id_field = $this->db_fields['id']; 
    418418        $parent_field = $this->db_fields['parent']; 
    419419     
     420        if ($depth > 0) { 
     421            //start the child delimiter 
     422            $cb_args = array_merge( array($output, $depth), $args); 
     423            $output = call_user_func_array(array(&$this, 'start_lvl'), $cb_args); 
     424        }  
     425             
    420426        //display this element 
    421427        $cb_args = array_merge( array($output, $element, $depth), $args); 
    422428        $output = call_user_func_array(array(&$this, 'start_el'), $cb_args); 
    423429 
    424         if ( !$children_elements ) { 
    425             //close off this element 
    426             $cb_args = array_merge( array($output, $element, $depth), $args); 
    427             $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 
    428             return $output;  
    429         } 
    430      
    431430        for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) { 
     431             
    432432            $child = $children_elements[$i]; 
    433              
    434433            if ( $child->$parent_field == $element->$id_field ) { 
    435434                 
    436                 array_splice( $children_elements, $i, 1 );  
    437                  
    438                 //start the child delimiter 
    439                 $cb_args = array_merge( array($output, $depth), $args); 
    440                 $output = call_user_func_array(array(&$this, 'start_lvl'), $cb_args); 
    441                  
     435                array_splice( $children_elements, $i, 1 ); 
    442436                $output = $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); 
    443                  
    444                 //end the child delimiter 
    445                 $cb_args = array_merge( array($output, $depth), $args); 
    446                 $output = call_user_func_array(array(&$this, 'end_lvl'), $cb_args); 
    447437                $i--;  
    448438            } 
    449439        } 
     440         
     441        //end this element 
     442        $cb_args = array_merge( array($output, $element, $depth), $args); 
     443        $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 
     444         
     445        if ($depth > 0) { 
     446            //end the child delimiter 
     447            $cb_args = array_merge( array($output, $depth), $args); 
     448            $output = call_user_func_array(array(&$this, 'end_lvl'), $cb_args); 
     449        } 
     450         
    450451        return $output;  
    451452    } 
     
    453454    /* 
    454455    * displays array of elements hierarchically 
     456    * it is a generic function which does not assume any existing order of elements 
    455457    * max_depth = -1 means flatly display every element  
    456458    * max_depth = 0  means display all levels  
     
    461463        $args = array_slice(func_get_args(), 2); 
    462464        $output = ''; 
     465 
     466        if ($max_depth < -1) //invalid parameter 
     467            return $output;  
    463468 
    464469        $id_field = $this->db_fields['id'];