Make WordPress Core

Ticket #7136: category_paging.diff

File category_paging.diff, 3.7 KB (added by ryan, 18 years ago)
  • wp-admin/includes/template.php

     
    44// Big Mess
    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);
    11                 if ( !empty($_GET['s']) )
     11                if ( !empty($_GET['s']) ) {
    1212                        $args['search'] = $_GET['s'];
     13                        $parent = -1;
     14                }
    1315                $categories = get_categories( $args );
    1416        }
    1517
     18        if ( !$categories )
     19                return false;
     20
    1621        $children = _get_term_hierarchy('category');
    1722
    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 );
     23        $start = ($page - 1) * $per_page;
     24        $end = $start + $per_page;
     25        $i = -1;
     26        ob_start();
     27        foreach ( $categories as $category ) {
     28                if ( $count >= $end )
     29                        break;
     30
     31                $i++;
     32
     33                if ( ($category->parent != $parent) && ( -1 != $parent) )
     34                        continue;
     35
     36                // If the page starts in a subtree, print the parents.
     37                if ( $count == $start && $category->parent > 0 ) {
     38                        $my_parents = array();
     39                        $my_parent = $category->parent;
     40                        while ( $my_parent) {
     41                                $my_parent = get_category($my_parent);
     42                                $my_parents[] = $my_parent;
     43                                if ( !$my_parent->parent )
     44                                        break;
     45                                $my_parent = $my_parent->parent;
    2546                        }
     47                        $num_parents = count($my_parents);
     48                        while( $my_parent = array_pop($my_parents) ) {
     49                                echo "\t" . _cat_row( $my_parent, $level - $num_parents );
     50                                $num_parents--;
     51                        }
    2652                }
    27                 $output = ob_get_contents();
    28                 ob_end_clean();
    2953
    30                 $output = apply_filters('cat_rows', $output);
     54                if ( $count >= $start )
     55                        echo "\t" . _cat_row( $category, $level );
    3156
    32                 echo $output;
    33         } else {
    34                 return false;
     57                unset($categories[$i]); // Prune the working set               
     58                $count++;
     59
     60                if ( isset($children[$category->term_id]) )
     61                        cat_rows( $category->term_id, $level + 1, $categories, $page, $per_page, $count );
     62
    3563        }
     64
     65        $output = ob_get_contents();
     66        ob_end_clean();
     67
     68        $output = apply_filters('cat_rows', $output);
     69
     70        echo $output;
    3671}
    3772
    3873function _cat_row( $category, $level, $name_override = false ) {
  • wp-admin/categories.php

     
    135135
    136136<div class="tablenav">
    137137
     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?>
     155
    138156<div class="alignleft">
    139157<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
    140158<?php wp_nonce_field('bulk-categories'); ?>
     
    156174        </thead>
    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>
    162181</table>
    163182</form>
    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>
    168192<br class="clear" />