I have three columns, each displaying 2 posts, each from different categories and each being a new query.

These three columns are shown on thier parent category page, which is set to display 6 posts per page.

$soundPosts = new WP_Query('posts_per_page=2&cat=4&paged=' . get_query_var( 'paged' ));
$viewsPosts = new WP_Query('posts_per_page=2&cat=5&paged=' . get_query_var( 'paged' ));
$wordsPosts = new WP_Query('posts_per_page=2&cat=6&paged=' . get_query_var( 'paged' ));

At the moment pagination kind of works, but not properly. It is using the pagination for the main parent category.

        <div class="navigation">
            <div class="left"><?php previous_posts_link('&#60; Previous') ?></div>
            <div class="right"><?php next_posts_link('Next &#62;','') ?></div>

The pagination kind of works, as the parent category contains the posts, and is set to show 6 posts, but it doesn't always work as the posts aren't always equally distributed throughout the columns.

How can I manually build the navigation links, so they run off the queries above, rather than the archive's default pagination? And how and the end of all records can I make the archive return a 404 page, for use with infinte scroll.

Also of note, I am aware of this question / answer, but don't think it is an accpetable solution, or is in fact the same setup I have currently.

Thanks alot for any pointers!

1 Answer 1


OK this is what I ended up with, that works well:

// get paged value.
$paged = get_query_var( 'paged' );
$maxPages = array();
$max = 0;

// Create the queries
$soundPosts = new WP_Query('posts_per_page=1&cat=4&paged=' . $paged);
$viewsPosts = new WP_Query('posts_per_page=1&cat=5&paged=' . $paged);
$wordsPosts = new WP_Query('posts_per_page=1&cat=6&paged=' . $paged);

// get max number of pages for each query

// get the max number of pages from all three.
$max = max($maxPages); 

// If we are out of posts, return 404
if ($paged > $max) {

// proceed as normal.

Then for the pagination links, just a bit of logic from the variables created to decide whether to show the links or not.

if ($paged > 0 && $paged < $max) { ?>
    <div class="left"><?php previous_posts_link('&#60; Previous') ?></div>
if ($paged <= $max) { ?>
    <div class="right"><?php next_posts_link('Next &#62;','') ?></div>
<?php } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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