phpwordpresspagination

Final posts not showing on last category page on wordpress site


I have a WordPress site that has a ton of posts on it, all categorized. I set up a new theme, with pagination (15 posts per page), so the user can cycle through each page. Some of the categories paginate fine. Others are missing the final page.

So, if a category has 66 posts ... the first 4 pages show 15 different posts. However, when I click to view page 5, the page says "no posts found". Where did the last 6 posts go? They still show up in my administration (as published and visible). However, other category pages do not have this issue - for example, I have a category with 42 post, and it has 3 page ... the last page of which has 12 of the final post.

So, the pagination seems to be working fine (since it clearly shows the correct number of pages, for the number of posts). Please take a look below at the code I have... this is code from my templated index.php page (I didnt set up a category.php page, because it lists very similarly to the homepage).

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // Page
$args = "posts_per_page=15&paged=".$paged; // Base query

$category = get_queried_object(); // Get Cat info
$thisCat = $category->term_id; // Get Cat ID (if exists)
$tagID = get_queried_object()->term_id; // Get Tag ID (if exists)
echo '<!-- paged: '.$paged.'-->';
echo '<!-- catID: '.$thisCat.'-->';
echo '<!-- tagID: '.$tagID.'-->';


if (is_home() || is_front_page()) { // HOMEPAGE   
    query_posts($args.'&orderby=rand');
    echo '<!-- args: '.$args.'&orderby=rand'.'-->';

} elseif ( is_search() ) { // SEARCH RESULTS ?>
    <?php 
    $search_query = get_search_query();
    query_posts($args.'&s='.$search_query);  
    echo "<!-- args: ".$args.'&s='.$search_query."-->"; ?>

    <h1>Search</h1>                    
    <div class="content_labels">
        <div class="content_label">SEARCH RESULTS FOR: <?php echo $s; ?></div>
    </div>
    <div class="clear" style="margin:0 0 10px 0;"></div>
    <div class="previouspage">
        <a href="javascript:history.back()"><< Previous Page</a>
    </div><?php 

} elseif( is_category() ) { // CATEGORY
    query_posts($args.'&cat='.$thisCat); 
    echo '<!-- args: '.$args.'&cat='.$thisCat.'-->'; ?>
    <div class="content_labels">
        <div class="content_label">Category:</div>
    </div>
    <h1><?php single_cat_title( '', true ); ?></h1>                    
    <div class="clear" style="margin:0 0 10px 0;"></div>
    <div class="previouspage">
        <a href="javascript:history.back()"><< Previous Page</a>
    </div><?php 

} elseif( is_tag()) { // TAGS
    echo '<!-- args: '.$args.'&tag_id='.$tagID.'-->'; 
    query_posts($args.'&tag_id='.$tagID); ?>
    <div class="content_labels">
        <div class="content_label">Tag:</div>
    </div>
    <h1><?php single_tag_title(); ?> </h1>                    
    <div class="clear" style="margin:0 0 10px 0;"></div>
    <div class="previouspage">
        <a href="javascript:history.back()">Previous Page</a>
    </div><?php
}

if ( have_posts() ) :
    $i=1; 
    while ( have_posts() ) : the_post(); ?>

     // PAGE CODE GOES HERE

     endwhile; ?>

    <?php base_pagination(); // PAGINATION CODE ?>

<?php endif; ?>     

Here is the pagination code, from my functions.php ... I don't think this is the issue...

function base_pagination() {
    global $wp_query;

    $big = 999999999; // This needs to be an unlikely integer

    // For more options and info view the docs for paginate_links()
    // http://codex.wordpress.org/Function_Reference/paginate_links
    $paginate_links = paginate_links( array(
        'base' => str_replace( $big, '%#%', get_pagenum_link($big) ),
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'mid_size' => 5
    ) );

    // Display the pagination if more than one page is found
    if ( $paginate_links ) {
        echo '<div class="pagination">';
        echo $paginate_links;
        echo '</div><!--// end .pagination -->';
    }
}

Can anyone see what is going wrong? I've been playing with this for several hours, and I can't seem to find a solution...


Solution

  • So, I did some digging, and tried some things... I couldn't find anything wrong with the code above. The query was correct (showing 15 per page, for each category archive page, etc.), and the pagination was working ... In the end, the default POSTS PER PAGE was conflicting with my own posts_per_page=15 query. Not sure WHERE this conflict was occurring (that is beyond my skills) - but I did learn how to stop it.

    Under SETTINGS - READING ... I just changed the "Blog pages show at most" to "15"

    This wasn't an ideal fix (since I don't know where this problem started, and I can't adjust custom "posts_per_page" if it differs from 15)... but my site now works how I want.