WordPress.org

Ready to get started?Download WordPress

Forums

Multipage get_categories function (4 posts)

  1. theone2k1
    Member
    Posted 3 years ago #

    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>';  }
    ?>
  2. pcs2112
    Member
    Posted 3 years ago #

    did anybody find a solution?

  3. docbrandes
    Member
    Posted 3 years ago #

    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!

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic