Changeset 8319
- Timestamp:
- 07/12/2008 03:40:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/template.php
r8296 r8319 526 526 527 527 /* 528 * displays pages in hierarchical order 528 * displays pages in hierarchical order with paging support 529 529 */ 530 531 530 function page_rows($pages, $pagenum = 1, $per_page = 20) { 532 531 $level = 0; … … 539 538 } 540 539 541 // splice pages into two parts: those without parent and those with parent 542 $top_level_pages = array(); 543 $children_pages = array(); 544 545 // If searching, ignore hierarchy and treat everything as top level, otherwise split 546 // into top level and children 540 /* 541 * arrange pages into two parts: top level pages and children_pages 542 * children_pages is two dimensional array, eg. 543 * children_pages[10][] contains all sub-pages whose parent is 10. 544 * It only takes O(N) to arrange this and it takes O(1) for subsequent lookup operations 545 * If searching, ignore hierarchy and treat everything as top level 546 */ 547 547 if ( empty($_GET['s']) ) { 548 549 $top_level_pages = array(); 550 $children_pages = array(); 551 548 552 foreach ( $pages as $page ) { 553 549 554 // catch and repair bad pages 550 555 if ( $page->post_parent == $page->ID ) { … … 557 562 $top_level_pages[] = $page; 558 563 else 559 $children_pages[ ] = $page;564 $children_pages[ $page->post_parent ][] = $page; 560 565 } 561 566 … … 566 571 $start = ($pagenum - 1) * $per_page; 567 572 $end = $start + $per_page; 573 568 574 foreach ( $pages as $page ) { 569 575 if ( $count >= $end ) 570 576 break; 571 577 572 $i++;573 574 578 if ( $count >= $start ) 575 579 echo "\t" . display_page_row( $page, $level ); … … 580 584 _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); 581 585 } 582 } 583 584 function _page_rows( $pages, &$count, $parent, $level, $pagenum, $per_page ) { 586 587 // if it is the last pagenum and there are orphaned pages, display them with paging as well 588 if ( isset($children_pages) && $count < $end ){ 589 foreach( $children_pages as $orphans ){ 590 foreach ( $orphans as $op ) { 591 if ( $count >= $end ) 592 break; 593 if ( $count >= $start ) 594 echo "\t" . display_page_row( $op, 0 ); 595 $count++; 596 } 597 } 598 } 599 } 600 601 /* 602 * Given a top level page ID, display the nested hierarchy of sub-pages 603 * together with paging support 604 */ 605 function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) { 606 607 if ( ! isset( $children_pages[$parent] ) ) 608 return; 609 585 610 $start = ($pagenum - 1) * $per_page; 586 611 $end = $start + $per_page; 587 $i = -1; 588 foreach ( $pages as $page ) { 612 613 foreach ( $children_pages[$parent] as $page ) { 614 589 615 if ( $count >= $end ) 590 616 break; 591 592 $i++; 593 594 if ( $page->post_parent != $parent ) 595 continue; 596 617 597 618 // If the page starts in a subtree, print the parents. 598 619 if ( $count == $start && $page->post_parent > 0 ) { … … 615 636 if ( $count >= $start ) 616 637 echo "\t" . display_page_row( $page, $level ); 617 618 unset($pages[$i]); // Prune the working set 638 619 639 $count++; 620 640 621 _page_rows( $pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); 622 } 641 _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); 642 } 643 644 unset( $children_pages[$parent] ); //required in order to keep track of orphans 623 645 } 624 646
Note: See TracChangeset
for help on using the changeset viewer.