diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php index d9fa2ff0d8..f9ff0ed717 100644 --- a/wp-admin/edit-pages.php +++ b/wp-admin/edit-pages.php @@ -68,7 +68,9 @@ printf( _c( '%1$s%2$s%3$s|You can reorder these: 1: Pages, 2: by {s}, 3: matchin
- + diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index fae8576313..c3983fe918 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -225,45 +225,90 @@ function wp_manage_posts_columns() { return $posts_columns; } -function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { - global $class, $post; +/* + * display one row if the page doesn't have any children + * otherwise, display the row and its children in subsequent rows + */ +function display_page_row( $page, &$children_pages, $level = 0 ) { + global $post; + static $class; + + $post = $page; + setup_postdata($page); - if (!$pages ) - $pages = get_pages( 'sort_column=menu_order' ); + $page->post_title = wp_specialchars( $page->post_title ); + $pad = str_repeat( '— ', $level ); + $id = (int) $page->ID; + $class = ('alternate' == $class ) ? '' : 'alternate'; - if (! $pages ) - return false; - - foreach ( $pages as $post) { - setup_postdata( $post); - if ( $hierarchy && ($post->post_parent != $parent) ) - continue; - - $post->post_title = wp_specialchars( $post->post_title ); - $pad = str_repeat( '— ', $level ); - $id = (int) $post->ID; - $class = ('alternate' == $class ) ? '' : 'alternate'; ?> - ID; ?> + ID; ?> - + - post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?> + post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $page->post_modified ); ?> " . __( 'Edit' ) . ""; } ?> " . __( 'Delete' ) . ""; } ?> post_parent == $id ) { + array_splice($children_pages, $i, 1); + display_page_row($child, $children_pages, $level+1); + $i--; + } } } +/* + * displays pages in hierarchical order + */ +function page_rows( $pages ) { + if ( ! $pages ) + $pages = get_pages( 'sort_column=menu_order' ); + + if ( ! $pages ) + return false; + + // splice pages into two parts: those without parent and those with parent + + $top_level_pages = array(); + $children_pages = array(); + + foreach ( $pages as $page ) { + if ( 0 == $page->post_parent ) + $top_level_pages[] = $page; + else + $children_pages[] = $page; + } + + foreach ( $top_level_pages as $page ) + display_page_row($page, $children_pages, 0); + + /* + * display the remaining children_pages which are orphans + * having orphan requires parental attention + */ + if ( count($children_pages) > 0 ) { + $empty_array = array(); + foreach ($children_pages as $orphan_page) + display_page_row($orphan_page, $empty_array, 0); + } +} + function user_row( $user_object, $style = '' ) { - if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) + if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) $user_object = new WP_User( (int) $user_object ); $email = $user_object->user_email; $url = $user_object->user_url; diff --git a/wp-includes/query.php b/wp-includes/query.php index 18edd10e61..90f222f646 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1113,7 +1113,7 @@ class WP_Query { $q['orderby'] = 'post_date '.$q['order']; } else { // Used to filter values - $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order'); + $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order', 'parent', 'ID'); $q['orderby'] = urldecode($q['orderby']); $q['orderby'] = addslashes_gpc($q['orderby']); $orderby_array = explode(' ',$q['orderby']); @@ -1123,11 +1123,16 @@ class WP_Query { for ($i = 0; $i < count($orderby_array); $i++) { // Only allow certain values for safety $orderby = $orderby_array[$i]; - if ( 'menu_order' != $orderby ) + if ( !('menu_order' == $orderby || 'ID' == $orderby )) $orderby = 'post_' . $orderby; if ( in_array($orderby_array[$i], $allowed_keys) ) - $q['orderby'] .= (($i == 0) ? '' : ',') . "$orderby {$q['order']}"; + $q['orderby'] .= (($i == 0) ? '' : ',') . $orderby; } + /* append ASC or DESC at the end */ + if ( !empty($q['orderby'])){ + $q['orderby'] .= " {$q['order']}"; + } + if ( empty($q['orderby']) ) $q['orderby'] = 'post_date '.$q['order']; }