Support » Plugins » Hacks » Multipage get_categories function

  • Hi, I used the following codes to list all the categories that I have on my site, but the issue is that I have too many categories (100+). So, I would like to paginate the category listing. (i.e 10 categories each page… etc) I don’t know how I would approach this using the get_categories function within WordPress. Help??? Thanks!

    <?php
    $args=array(
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $categories=get_categories($args);
      foreach($categories as $category) {
        echo '<p>Category: <a>term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
        echo '<p> Description:'. $category->description . '</p>';
        echo '<p> Post Count: '. $category->count . '</p>';  }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • did anybody find a solution?

    docbrandes

    (@docbrandes)

    I have this same issue … I’m using a get_categories array and am returning a list of 100+ cats, so I want to paginate the list. Please help! There’s got to be a way to do this!

    Use get_terms, create your own paging and adjust the offset as necessary..

    For example purposes.

    $catnum = 5;
    $catpage = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    $offset = ($catpage - 1) * $catnum;
    $cats = get_terms( array(
      'orderby' => 'name',
      'order' => 'ASC',
      'number' => $catnum,
      'offset' => $offset
    ) );

    I don’t have time to follow up on this or test code, so i hope the example helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multipage get_categories function’ is closed to new replies.