[resolved] How do you limit posts on category page and allow pagination to work? (5 posts)

  1. xxangel
    Posted 6 years ago #

    I'm creating a template separate from my main website for a single category. This can be viewed here.

    However, when I try to limit the number of posts displayed on the category page with

    <?php query_posts($query_string . "&posts_per_page=1"); ?>

    the pagination stops working. When I go to WEBSITE/page/2/, it says that there is no post.

    You can check it out by clicking on "previous posts" on the front page.

    When you click on the name of the post, you will be at the single page post. The next_post_link and previous_post_link works fine there and goes to the next or previous post of the same category.

    Does anyone know a way to limit the post number without destroying the pagination? Thanks!

  2. Mark / t31os

    Posted 6 years ago #

    if(!$wp_query) global $wp_query;
    query_posts( array_merge( array( 'posts_per_page' => 1 ) , $wp_query->query ) );
  3. xxangel
    Posted 6 years ago #

    I tried that before and it doesn't work. It still goes to a 404 page error.

  4. xxangel
    Posted 6 years ago #

    Nevermind, thank you so much for your help!

    For anyone else who has the problem, remember to put the code BEFORE the loop!

  5. Drew Baker
    Posted 5 years ago #

    Thanks for this, solved a problem for me. I wonder why I couldn't I just make my category.php file look like this? :

    <?php query_posts('posts_per_page=5'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    Do something
    <?php endwhile; ?>
    <?php else : ?>
    Do something else
    <?php endif; ?>

    That would make any category page show all posts from all categories. Strange behavior. I'm using WP 3.0.1.


Topic Closed

This topic has been closed to new replies.

About this Topic