Changeset 8078

Show
Ignore:
Timestamp:
06/13/08 23:22:29 (5 months ago)
Author:
ryan
Message:

Add paging to Manage->Categories. fixes #7136

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/categories.php

    r7883 r8078  
    135135 
    136136<div class="tablenav"> 
     137 
     138<?php 
     139$pagenum = absint( $_GET['pagenum'] ); 
     140if ( empty($pagenum) ) 
     141    $pagenum = 1; 
     142if( !$catsperpage || $catsperpage < 0 ) 
     143    $catsperpage = 20; 
     144 
     145$page_links = paginate_links( array( 
     146    'base' => add_query_arg( 'pagenum', '%#%' ), 
     147    'format' => '', 
     148    'total' => ceil(wp_count_terms('category') / $catsperpage), 
     149    'current' => $pagenum 
     150)); 
     151 
     152if ( $page_links ) 
     153    echo "<div class='tablenav-pages'>$page_links</div>"; 
     154?> 
    137155 
    138156<div class="alignleft"> 
     
    157175    <tbody id="the-list" class="list:cat"> 
    158176<?php 
    159 cat_rows(); 
     177$categories = array(); 
     178cat_rows(0, 0, $categories, $pagenum, $catsperpage); 
    160179?> 
    161180    </tbody> 
     
    164183 
    165184<div class="tablenav"> 
     185 
     186<?php 
     187if ( $page_links ) 
     188    echo "<div class='tablenav-pages'>$page_links</div>"; 
     189?> 
    166190<br class="clear" /> 
    167191</div> 
  • trunk/wp-admin/includes/template.php

    r7956 r8078  
    55// 
    66 
    7 // Dandy new recursive multiple category stuff. 
    8 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { 
    9     if ( !$categories ) { 
     7// Ugly recursive category stuff. 
     8function cat_rows( $parent = 0, $level = 0, &$categories = 0, $page = 1, $per_page = 20, &$count = 0 ) { 
     9    if ( empty($categories) ) { 
    1010        $args = array('hide_empty' => 0); 
    1111        if ( !empty($_GET['s']) ) 
     
    1414    } 
    1515 
     16    if ( !$categories ) 
     17        return false; 
     18 
    1619    $children = _get_term_hierarchy('category'); 
    1720 
    18     if ( $categories ) { 
    19         ob_start(); 
    20         foreach ( $categories as $category ) { 
    21             if ( $category->parent == $parent) { 
    22                 echo "\t" . _cat_row( $category, $level ); 
    23                 if ( isset($children[$category->term_id]) ) 
    24                     cat_rows( $category->term_id, $level +1, $categories ); 
     21    $start = ($page - 1) * $per_page; 
     22    $end = $start + $per_page; 
     23    $i = -1; 
     24    ob_start(); 
     25    foreach ( $categories as $category ) { 
     26        if ( $count >= $end ) 
     27            break; 
     28 
     29        $i++; 
     30 
     31        if ( $category->parent != $parent ) 
     32            continue; 
     33 
     34        // If the page starts in a subtree, print the parents. 
     35        if ( $count == $start && $category->parent > 0 ) { 
     36            $my_parents = array(); 
     37            $my_parent = $category->parent; 
     38            while ( $my_parent) { 
     39                $my_parent = get_category($my_parent); 
     40                $my_parents[] = $my_parent; 
     41                if ( !$my_parent->parent ) 
     42                    break; 
     43                $my_parent = $my_parent->parent; 
    2544            } 
    26         } 
    27         $output = ob_get_contents(); 
    28         ob_end_clean(); 
    29  
    30         $output = apply_filters('cat_rows', $output); 
    31  
    32         echo $output; 
    33     } else { 
    34         return false; 
    35     } 
     45            $num_parents = count($my_parents); 
     46            while( $my_parent = array_pop($my_parents) ) { 
     47                echo "\t" . _cat_row( $my_parent, $level - $num_parents ); 
     48                $num_parents--; 
     49            } 
     50        } 
     51 
     52        if ( $count >= $start ) 
     53            echo "\t" . _cat_row( $category, $level ); 
     54 
     55        unset($categories[$i]); // Prune the working set         
     56        $count++; 
     57 
     58        if ( isset($children[$category->term_id]) ) 
     59            cat_rows( $category->term_id, $level + 1, $categories, $page, $per_page, $count ); 
     60 
     61    } 
     62 
     63    $output = ob_get_contents(); 
     64    ob_end_clean(); 
     65 
     66    $output = apply_filters('cat_rows', $output); 
     67 
     68    echo $output; 
    3669} 
    3770