Grow your CSS skills. Land your dream job.

paginate get_categories ?

  • # October 9, 2012 at 8:24 pm

    I can’t figure out how to paginate my categories.php. I have this special loop. I have to have it done this way. I am returning three posts and need to get the pagination working to display the rest of the posts

    Here is the full loop
    $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
    //get the child categories and only display 3 posts
    $allcats = get_categories(array(‘child_of’ => get_query_var(‘cat’), ‘number’ => 3,’order’=> ‘asc’, ‘paged’ => $paged));
    foreach ($allcats as $cat) :
    $args = array(
    ‘category__in’ => array($cat->term_id),
    );

    $customInCatQuery = new WP_Query($args);

    if ($customInCatQuery->have_posts()) :
    echo ‘

    ‘;

    ?>

    < ?php else :
    echo ‘No post published in:’.$cat->name;
    endif;
    wp_reset_query();
    endforeach;

    # October 9, 2012 at 10:50 pm

    You need to use [get_query_var()](http://codex.wordpress.org/Function_Reference/get_query_var “get_query_var”)

    # October 9, 2012 at 10:58 pm

    I am using that, it’s not working. I will edit the code to show that above

    # October 9, 2012 at 10:58 pm

    Example:

    $customInCatQuery = new WP_Query($args, ‘paged=’ . get_query_var( ‘paged’ ) );

    # October 9, 2012 at 11:01 pm

    I don’t think that will work. I will try it now though. But I can’t use the wp_query. The only way I can seem to get the child categories is by using the foreach loop. I just tried using child_of in a wp_query and got nothing back. I tried to remove the foreach $allcats loop above and replace it with wp_query and I got three posts saying “No post published”

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".