Forums

pagination issue - caused by 'posts_per_page' parameter (4 posts)

  1. mjoanisse
    Member
    Posted 1 year ago #

    Hi -
    I'm experiencing a custom 'query' pagination issue, relating to the 'posts_per_page' parameter.

    I have my 'category' template, using a custom query on the loop, with one of the parameters being 'posts_per_page'.

    When i click to next page, /page/2/ - it returns a 404 (the one I've setup).

    When i REMOVE the 'posts_per_page' parameter from this query, it works again ... (I've tested by lowering default stated in the 'reading settings' of dashboard panel.

    Any ideas / solutions? I did read this, which is a 'quick' fix, but really doesn't give me the logical reasoning to the issue.

    Cheers!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
        'category_name' => 'News',
        'paged' => $paged
    );
    query_posts($args);
    ?>
  3. mjoanisse
    Member
    Posted 1 year ago #

    Thank you esmi -
    I have the pagination query in place already, which is working fine in other areas apart from category template.

    Here is what I have ..

    <?php
    		if (is_category(15)) {
    		$queried_category = 15;
    		} else if (is_category(13)) {
    		$queried_category = 13;
    		} else if (is_category(18)) {
    		$queried_category = 18;
    		}
    
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // allow for pagination
    
    		$args = array (
    		'cat' => $queried_category,
    		//'posts_per_page' => 3,
    		'paged' => $paged
    		);
    
    		query_posts($args);
    		?>
    
            <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>
            // content here
            <?php endwhile; ?>
    
            <div class="pagination">
            <?php previous_posts_link('< previous page', 0); ?>
            <?php next_posts_link('next page >', 0); ?>
            </div><!--End pagination-->
    
            <?php else : endif; ?>
  4. ms-studio
    Member
    Posted 1 year ago #

    Indeed, it looks like the pagination function doesn't fully "get" that the posts_per_page parameter has changed.

    Let's say for instance that i have a category with 50 posts, and have set the default limit to 20. If i am on the category page, that would result normally in 3 paginated pages (20 + 20 + 10).

    Now, if we add a "posts_per_page=5" to the query for this category page, the pagination will show 10 pages, which seems logical (10*5 = 50).

    The 3 first pagination links will work fine, but the following ones will result in a 404 page. It looks like at some place in the command chain, the system still thinks that there are only 3 pages rather than 10.

    A smart fix for this would be highly welcome -- for now i simplify my life by using the default posts_per_page on all paginated pages, and using custom posts_per_page values only when there's no pagination needed ...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags