3 Columns, 3 Categories, One Archive, and Pagination

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.

Read More
$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('< Previous') ?></div>
            <div class="right"><?php next_posts_link('Next >','') ?></div>
        </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!

Related posts

Leave a Reply

1 comment

  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
    array_push($maxPages,$soundPosts->max_num_pages);
    array_push($maxPages,$viewsPosts->max_num_pages);
    array_push($maxPages,$wordsPosts->max_num_pages);
    
    // get the max number of pages from all three.
    $max = max($maxPages); 
    
    // If we are out of posts, return 404
    if ($paged > $max) {
    $wp_query->set_404();
    status_header('404');
    }
    
    // proceed as normal.
    get_header(); 
    

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

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