Add paging to Manage->Pages. see #6561

git-svn-id: http://svn.automattic.com/wordpress/trunk@8089 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-06-15 00:45:01 +00:00
parent d9d0a899db
commit d1be6b2a32
2 changed files with 105 additions and 44 deletions

View File

@ -118,6 +118,25 @@ endif;
<div class="tablenav">
<?php
$pagenum = absint( $_GET['pagenum'] );
if ( empty($pagenum) )
$pagenum = 1;
if( !$per_page || $pre_page < 0 )
$per_page = 20;
$num_pages = ceil(count($posts) / $per_page);
$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '',
'total' => $num_pages,
'current' => $pagenum
));
if ( $page_links )
echo "<div class='tablenav-pages'>$page_links</div>";
?>
<div class="alignleft">
<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
<?php wp_nonce_field('bulk-pages'); ?>
@ -151,7 +170,7 @@ if ($posts) {
</tr>
</thead>
<tbody>
<?php page_rows($posts); ?>
<?php page_rows($posts, $pagenum, $per_page); ?>
</tbody>
</table>
@ -169,6 +188,10 @@ if ($posts) {
?>
<div class="tablenav">
<?php
if ( $page_links )
echo "<div class='tablenav-pages'>$page_links</div>";
?>
<br class="clear" />
</div>

View File

@ -398,7 +398,7 @@ function wp_manage_pages_columns() {
* 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 ) {
function display_page_row( $page, $level = 0 ) {
global $post;
static $class;
@ -522,66 +522,104 @@ foreach ($posts_columns as $column_name=>$column_display_name) {
</tr>
<?php
if ( ! $children_pages )
return true;
for ( $i = 0; $i < count($children_pages); $i++ ) {
$child = $children_pages[$i];
if ( $child->post_parent == $id ) {
array_splice($children_pages, $i, 1);
display_page_row($child, $children_pages, $level+1);
$i = -1; //as numeric keys in $children_pages are not preserved after splice
}
}
}
/*
* displays pages in hierarchical order
*/
function page_rows( $pages ) {
if ( ! $pages )
function page_rows($pages, $pagenum = 1, $per_page = 20) {
$level = 0;
if ( ! $pages ) {
$pages = get_pages( array('sort_column' => 'menu_order') );
if ( ! $pages )
return false;
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 ) {
// catch and repair bad pages
if ( $page->post_parent == $page->ID ) {
$page->post_parent = 0;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
clean_page_cache( $page->ID );
// If searching, ignore hierarchy and treat everything as top level, otherwise split
// into top level and children
if ( empty($_GET['s']) ) {
foreach ( $pages as $page ) {
// catch and repair bad pages
if ( $page->post_parent == $page->ID ) {
$page->post_parent = 0;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
clean_page_cache( $page->ID );
}
if ( 0 == $page->post_parent )
$top_level_pages[] = $page;
else
$children_pages[] = $page;
}
if ( 0 == $page->post_parent )
$top_level_pages[] = $page;
else
$children_pages[] = $page;
$pages = &$top_level_pages;
}
foreach ( $top_level_pages as $page )
display_page_row($page, $children_pages, 0);
$count = 0;
$start = ($pagenum - 1) * $per_page;
$end = $start + $per_page;
foreach ( $pages as $page ) {
if ( $count >= $end )
break;
/*
* 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 ) {
clean_page_cache( $orphan_page->ID);
display_page_row( $orphan_page, $empty_array, 0 );
$i++;
if ( $count >= $start )
echo "\t" . display_page_row( $page, $level );
$count++;
if ( isset($children_pages) )
_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
}
}
function _page_rows( $pages, &$count, $parent, $level, $pagenum, $per_page ) {
$start = ($pagenum - 1) * $per_page;
$end = $start + $per_page;
$i = -1;
foreach ( $pages as $page ) {
if ( $count >= $end )
break;
$i++;
if ( $page->post_parent != $parent )
continue;
// If the page starts in a subtree, print the parents.
if ( $count == $start && $page->post_parent > 0 ) {
$my_parents = array();
$my_parent = $page->post_parent;
while ( $my_parent) {
$my_parent = get_post($my_parent);
$my_parents[] = $my_parent;
if ( !$my_parent->post_parent )
break;
$my_parent = $my_parent->post_parent;
}
$num_parents = count($my_parents);
while( $my_parent = array_pop($my_parents) ) {
echo "\t" . display_page_row( $my_parent, $level - $num_parents );
$num_parents--;
}
}
}
if ( $count >= $start )
echo "\t" . display_page_row( $page, $level );
unset($pages[$i]); // Prune the working set
$count++;
_page_rows( $pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
}
}
function user_row( $user_object, $style = '', $role = '' ) {