Changeset 8089
- Timestamp:
- 06/15/2008 12:45:01 AM (17 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/edit-pages.php
r7998 r8089 118 118 119 119 <div class="tablenav"> 120 121 <?php 122 $pagenum = absint( $_GET['pagenum'] ); 123 if ( empty($pagenum) ) 124 $pagenum = 1; 125 if( !$per_page || $pre_page < 0 ) 126 $per_page = 20; 127 128 $num_pages = ceil(count($posts) / $per_page); 129 $page_links = paginate_links( array( 130 'base' => add_query_arg( 'pagenum', '%#%' ), 131 'format' => '', 132 'total' => $num_pages, 133 'current' => $pagenum 134 )); 135 136 if ( $page_links ) 137 echo "<div class='tablenav-pages'>$page_links</div>"; 138 ?> 120 139 121 140 <div class="alignleft"> … … 152 171 </thead> 153 172 <tbody> 154 <?php page_rows($posts ); ?>173 <?php page_rows($posts, $pagenum, $per_page); ?> 155 174 </tbody> 156 175 </table> … … 170 189 171 190 <div class="tablenav"> 191 <?php 192 if ( $page_links ) 193 echo "<div class='tablenav-pages'>$page_links</div>"; 194 ?> 172 195 <br class="clear" /> 173 196 </div> -
trunk/wp-admin/includes/template.php
r8086 r8089 399 399 * otherwise, display the row and its children in subsequent rows 400 400 */ 401 function display_page_row( $page, &$children_pages,$level = 0 ) {401 function display_page_row( $page, $level = 0 ) { 402 402 global $post; 403 403 static $class; … … 523 523 524 524 <?php 525 526 if ( ! $children_pages )527 return true;528 529 for ( $i = 0; $i < count($children_pages); $i++ ) {530 531 $child = $children_pages[$i];532 533 if ( $child->post_parent == $id ) {534 array_splice($children_pages, $i, 1);535 display_page_row($child, $children_pages, $level+1);536 $i = -1; //as numeric keys in $children_pages are not preserved after splice537 }538 }539 525 } 540 526 … … 542 528 * displays pages in hierarchical order 543 529 */ 544 function page_rows( $pages ) { 545 if ( ! $pages ) 530 531 function page_rows($pages, $pagenum = 1, $per_page = 20) { 532 $level = 0; 533 534 if ( ! $pages ) { 546 535 $pages = get_pages( array('sort_column' => 'menu_order') ); 547 536 548 if ( ! $pages ) 549 return false; 537 if ( ! $pages ) 538 return false; 539 } 550 540 551 541 // splice pages into two parts: those without parent and those with parent 552 553 542 $top_level_pages = array(); 554 543 $children_pages = array(); 555 544 545 // If searching, ignore hierarchy and treat everything as top level, otherwise split 546 // into top level and children 547 if ( empty($_GET['s']) ) { 548 foreach ( $pages as $page ) { 549 // catch and repair bad pages 550 if ( $page->post_parent == $page->ID ) { 551 $page->post_parent = 0; 552 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) ); 553 clean_page_cache( $page->ID ); 554 } 555 556 if ( 0 == $page->post_parent ) 557 $top_level_pages[] = $page; 558 else 559 $children_pages[] = $page; 560 } 561 562 $pages = &$top_level_pages; 563 } 564 565 $count = 0; 566 $start = ($pagenum - 1) * $per_page; 567 $end = $start + $per_page; 556 568 foreach ( $pages as $page ) { 557 558 // catch and repair bad pages 559 if ( $page->post_parent == $page->ID ) { 560 $page->post_parent = 0; 561 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) ); 562 clean_page_cache( $page->ID ); 563 } 564 565 if ( 0 == $page->post_parent ) 566 $top_level_pages[] = $page; 567 else 568 $children_pages[] = $page; 569 } 570 571 foreach ( $top_level_pages as $page ) 572 display_page_row($page, $children_pages, 0); 573 574 /* 575 * display the remaining children_pages which are orphans 576 * having orphan requires parental attention 577 */ 578 if ( count($children_pages) > 0 ) { 579 $empty_array = array(); 580 foreach ( $children_pages as $orphan_page ) { 581 clean_page_cache( $orphan_page->ID); 582 display_page_row( $orphan_page, $empty_array, 0 ); 583 } 584 } 569 if ( $count >= $end ) 570 break; 571 572 $i++; 573 574 if ( $count >= $start ) 575 echo "\t" . display_page_row( $page, $level ); 576 577 $count++; 578 579 if ( isset($children_pages) ) 580 _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); 581 } 582 } 583 584 function _page_rows( $pages, &$count, $parent, $level, $pagenum, $per_page ) { 585 $start = ($pagenum - 1) * $per_page; 586 $end = $start + $per_page; 587 $i = -1; 588 foreach ( $pages as $page ) { 589 if ( $count >= $end ) 590 break; 591 592 $i++; 593 594 if ( $page->post_parent != $parent ) 595 continue; 596 597 // If the page starts in a subtree, print the parents. 598 if ( $count == $start && $page->post_parent > 0 ) { 599 $my_parents = array(); 600 $my_parent = $page->post_parent; 601 while ( $my_parent) { 602 $my_parent = get_post($my_parent); 603 $my_parents[] = $my_parent; 604 if ( !$my_parent->post_parent ) 605 break; 606 $my_parent = $my_parent->post_parent; 607 } 608 $num_parents = count($my_parents); 609 while( $my_parent = array_pop($my_parents) ) { 610 echo "\t" . display_page_row( $my_parent, $level - $num_parents ); 611 $num_parents--; 612 } 613 } 614 615 if ( $count >= $start ) 616 echo "\t" . display_page_row( $page, $level ); 617 618 unset($pages[$i]); // Prune the working set 619 $count++; 620 621 _page_rows( $pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); 622 } 585 623 } 586 624
Note: See TracChangeset
for help on using the changeset viewer.