• I’ve looked at many of the previous category loop related topics on the forum but I’ve had no luck sorting this out.

    Essentially I’m running this query within category.php but I cannot get the pagination to work. If I have 6 posts, it correctly breaks down the posts into 3 per page and pagenavi shows 2 pages, however clicking on the page 2 link returns a page not found error. If I were to have three pages, pages 1 and 2 would work, but page 3 wouldn’t. It’s the last page in all cases that doesn’t work. Removing the “posts_per_page” option and setting the number of posts per page via Settings > Reading does work, but I need to specify it from the page itself. Hopefully someone can help.

    <?php
    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    query_posts($query_string.'&posts_per_page=3&paged='.$paged.'&cat='.$current_cat); if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    CODE HERE
    
    <?php endwhile; ?>
    <?php wp_pagenavi(); ?>
    <?php endif; wp_reset_query(); ?>
Viewing 3 replies - 16 through 18 (of 18 total)
  • Just a thought.

    Could it be that you are altering the query in between two pagination nav calls.

    If so the nav above the loop would be getting the paged values for the original query and the one below the loop would be getting paged values for your custom query. If this is the case creating your custom query above the top nav call should solve this.

    -Gene

    Thank you for reply emhr.

    I don;t think so, here is the 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; ?>

    Hi guys, just to say thanks. I got a similar script with a custom pagination and custom order in the category.php, maybe this can help others:

    [resolved] its possible to swicth the wp_query on category.php?

    @mark/t31os, why I cannot put “order” and “orderby” to work with query_posts? I don’t get it.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Pagination in custom query for category.php not working’ is closed to new replies.