Page walker fixes from hailin. fixes #5498

git-svn-id: http://svn.automattic.com/wordpress/trunk@6456 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-12-21 18:49:20 +00:00
parent 19471ad3ab
commit 131a6c0923
3 changed files with 3344 additions and 13 deletions

View File

@ -466,11 +466,14 @@ class Walker {
if ($max_depth < -1) //invalid parameter
return $output;
if (empty($elements)) //nothing to walk
return $output;
$id_field = $this->db_fields['id'];
$parent_field = $this->db_fields['parent'];
$flat = ($max_depth == -1) ? true : false;
if ( $flat ) {
// flat display
if ( -1 == $max_depth ) {
$empty_array = array();
foreach ( $elements as $e )
$output = $this->display_element( $e, $empty_array, 1, 0, $args, $output );
@ -481,10 +484,8 @@ class Walker {
* need to display in hierarchical order
* splice elements into two buckets: those without parent and those with parent
*/
$top_level_elements = array();
$children_elements = array();
foreach ( $elements as $e) {
if ( 0 == $e->$parent_field )
$top_level_elements[] = $e;
@ -492,6 +493,23 @@ class Walker {
$children_elements[] = $e;
}
/*
* none of the elements is top level
* the first one must be root of the sub elements
*/
if ( !$top_level_elements ) {
$root = $children_elements[0];
for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) {
$child = $children_elements[$i];
if ($root->$parent_field == $child->$parent_field )
$top_level_elements[] = $child;
array_splice( $children_elements, $i, 1 );
$i--;
}
}
foreach ( $top_level_elements as $e )
$output = $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );

File diff suppressed because one or more lines are too long

View File

@ -77,7 +77,7 @@ class WP_Scripts {
$this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
$this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.1.4');
$this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.2b');
$this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '1.0.3');
$this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2');