1

I was wondering if I can paginate wp_list_categories? I had a go with paginate_links but no luck. Or is there a good workaround? Thank you!!

<?php   $orderby = 'name';
    $show_count = 0;
    $pad_counts = 0;
    $hierarchical = 1;
    $taxonomy = 'categories';
    $title = '';
    $exclude = '16';

    $args = array(
    'orderby' => $orderby,
    'show_count' => $show_count,
    'pad_counts' => $pad_counts,
    'hierarchical' => $hierarchical,
    'taxonomy' => $taxonomy,
    'title_li' => $title,
    'exclude' => $exclude,
    'hide_empty' => 0
    );
    ?>
    <ul class="resourcelist">
    <?php wp_list_categories($args); ?>
    </ul> 
3

OK, after no luck with wp_list_categories, I resorted to get_categories to get the pagination working. I hope this helps someone.

<?php
    $args = array(
            'taxonomy' => 'categories',
            'orderby' => 'term_group',
            'hide_empty' => 0,
            'hierarchical' => 1,
            'exclude' => '16',
            'parent' => '0',
    );
    $categories = get_categories($args);
    $numOfItems = 60;
    $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
    $to = $page * $numOfItems;
    $current = $to - $numOfItems;
    $total = sizeof($categories);

            echo '<ul class="content">';

    for ($i=$current; $i<$to; ++$i) {

        $category = $categories[$i];

        if ($category->name) { echo '<li><a href="' . get_term_link($category->slug, 'categories') . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>';}

    }

            echo '</ul>';

    unset($category);
    echo paginate_links( array(
        'base' => add_query_arg( 'cpage', '%#%' ),
        'format' => '',
        'prev_text' => __('&laquo;'),
        'next_text' => __('&raquo;'),
        'total' => ceil($total / $numOfItems),
        'current' => $page
    ));

    ?>
1
  • 1
    you need to change the $numOfItems to get your desired number of items per page, currently it is set to 60. – uknowit2 Jul 4 '12 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.