Add paging to Manage->Categories. fixes #7136

git-svn-id: https://develop.svn.wordpress.org/trunk@8078 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-06-13 23:22:29 +00:00
parent c2b68223db
commit b0494981e5
2 changed files with 74 additions and 17 deletions

View File

@ -135,6 +135,24 @@ endif; ?>
<div class="tablenav"> <div class="tablenav">
<?php
$pagenum = absint( $_GET['pagenum'] );
if ( empty($pagenum) )
$pagenum = 1;
if( !$catsperpage || $catsperpage < 0 )
$catsperpage = 20;
$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '',
'total' => ceil(wp_count_terms('category') / $catsperpage),
'current' => $pagenum
));
if ( $page_links )
echo "<div class='tablenav-pages'>$page_links</div>";
?>
<div class="alignleft"> <div class="alignleft">
<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" /> <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
<?php wp_nonce_field('bulk-categories'); ?> <?php wp_nonce_field('bulk-categories'); ?>
@ -156,13 +174,19 @@ endif; ?>
</thead> </thead>
<tbody id="the-list" class="list:cat"> <tbody id="the-list" class="list:cat">
<?php <?php
cat_rows(); $categories = array();
cat_rows(0, 0, $categories, $pagenum, $catsperpage);
?> ?>
</tbody> </tbody>
</table> </table>
</form> </form>
<div class="tablenav"> <div class="tablenav">
<?php
if ( $page_links )
echo "<div class='tablenav-pages'>$page_links</div>";
?>
<br class="clear" /> <br class="clear" />
</div> </div>
<br class="clear" /> <br class="clear" />

View File

@ -4,35 +4,68 @@
// Big Mess // Big Mess
// //
// Dandy new recursive multiple category stuff. // Ugly recursive category stuff.
function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { function cat_rows( $parent = 0, $level = 0, &$categories = 0, $page = 1, $per_page = 20, &$count = 0 ) {
if ( !$categories ) { if ( empty($categories) ) {
$args = array('hide_empty' => 0); $args = array('hide_empty' => 0);
if ( !empty($_GET['s']) ) if ( !empty($_GET['s']) )
$args['search'] = $_GET['s']; $args['search'] = $_GET['s'];
$categories = get_categories( $args ); $categories = get_categories( $args );
} }
if ( !$categories )
return false;
$children = _get_term_hierarchy('category'); $children = _get_term_hierarchy('category');
if ( $categories ) { $start = ($page - 1) * $per_page;
$end = $start + $per_page;
$i = -1;
ob_start(); ob_start();
foreach ( $categories as $category ) { foreach ( $categories as $category ) {
if ( $category->parent == $parent) { if ( $count >= $end )
break;
$i++;
if ( $category->parent != $parent )
continue;
// If the page starts in a subtree, print the parents.
if ( $count == $start && $category->parent > 0 ) {
$my_parents = array();
$my_parent = $category->parent;
while ( $my_parent) {
$my_parent = get_category($my_parent);
$my_parents[] = $my_parent;
if ( !$my_parent->parent )
break;
$my_parent = $my_parent->parent;
}
$num_parents = count($my_parents);
while( $my_parent = array_pop($my_parents) ) {
echo "\t" . _cat_row( $my_parent, $level - $num_parents );
$num_parents--;
}
}
if ( $count >= $start )
echo "\t" . _cat_row( $category, $level ); echo "\t" . _cat_row( $category, $level );
unset($categories[$i]); // Prune the working set
$count++;
if ( isset($children[$category->term_id]) ) if ( isset($children[$category->term_id]) )
cat_rows( $category->term_id, $level +1, $categories ); cat_rows( $category->term_id, $level + 1, $categories, $page, $per_page, $count );
}
} }
$output = ob_get_contents(); $output = ob_get_contents();
ob_end_clean(); ob_end_clean();
$output = apply_filters('cat_rows', $output); $output = apply_filters('cat_rows', $output);
echo $output; echo $output;
} else {
return false;
}
} }
function _cat_row( $category, $level, $name_override = false ) { function _cat_row( $category, $level, $name_override = false ) {