Support » Fixing WordPress » Template: how to show paginated posts?

  • Resolved joaoramos


    I’ve just implemented posts_nav_link(); after my gallery loop, but when I click “Previous Page” or “Next Page” it shows me the exact same gallery posts. How do I make it refresh the page with the previous or next posts? I’m sorry if I wasn’t clear enough.

    Here’s how my archive.php looks like:

    <?php get_header(); ?>
    				get_template_part( 'loop', 'gallery' );
    <?php get_footer(); ?>

    And here’s how my loop-gallery.php looks like:

    <?php if (have_posts()) : ?>
    	<?php query_posts('post_type=post&offset=0&posts_per_page=5'); ?>
    	<ul class="gallery">
    		<?php while (have_posts()) : the_post(); ?>
    			<li class="mosaic-block bar">
    				<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="mosaic-overlay">
    					<h3><?php the_title(); ?></h3>
    				<div class="mosaic-backdrop">
    						if (has_post_thumbnail()) {
    							$size = array(150, 150);
    		<?php endwhile; ?>
    	<?php posts_nav_link(); ?>
    	<?php else : ?>
    		<h4>Nothing Found</h4>
    <?php endif; ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • You need to check the paged query var…example:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string.'&posts_per_page=5&paged=' . $paged);

    Thanks, Michael. The pagination recognizes when there are more posts to show, but the posts are still not being loaded—every time I go back and forth on the pagination, I always see the same posts. Any suggestions?



    Forum Moderator

    in your code:

    <?php query_posts('post_type=post&offset=0&posts_per_page=5'); ?>

    the ‘offset’ parameter does not work with pagination; offset=0 is redundant in any case.

    can you confirm what code you tried?

    This is the code I’m using now. I’ only took out the offset=0. I can see that the links still recognize when there’s more posts to paginate—but the problem persists and I always see the same posts, no matter which page I am (example, example/page/2, example/page/3, etc). Any suggestions?

    I have same problems …. how can I solve it ?

    I completely forgot that I was using a $variable on my query, lol. All I had to do was change paged=$paged to paged='.$paged.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Template: how to show paginated posts?’ is closed to new replies.