• I have 30 posts in a category. I want to show 9 on a page with previous and next buttons. My simplified code is…

    <?php $my_query = new WP_Query('category_name=' .single_cat_title( '', false ).'&posts_per_page=9'); while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <p><?php the_title(); ?></p>
    
    <?php previous_posts_link( '< previous'); ?> 
    
    <?php next_posts_link( 'next >'); ?> 
    
    <?php endwhile; // End the loop. ?>

    …this shows 9 posts as expected, but the when i click the ‘next’ link I get &paged=2 added to the URL but the page just displays the same 9 posts again. I assume I need something in my search query to advance the count but I don’t know what

Viewing 1 replies (of 1 total)
  • Thread Starter paulwillis

    (@paulwillis)

    To answer my own question I needed…

    &paged='.$paged.'

    in my query so…

    <?php $my_query = new WP_Query('category_name=' .single_cat_title( '', false ).'&posts_per_page=9'); while ($my_query->have_posts()) : $my_query->the_post(); ?>

    …became…

    <?php $my_query = new WP_Query('category_name=' .single_cat_title( '', false ).'&posts_per_page=9&paged='.$paged.''); while ($my_query->have_posts()) : $my_query->the_post(); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Trouble getting previous and next links working’ is closed to new replies.