Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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> 
share|improve this question
add comment

1 Answer

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
    ));

    ?>
share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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