[resolved] Template: how to show paginated posts? (7 posts)

  1. joaoramos
    Posted 4 years ago #

    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; ?>
  2. MichaelH
    Posted 4 years ago #

    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);
  3. joaoramos
    Posted 4 years ago #

    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?

  4. Michael
    Part-Time Forum Moderator
    Posted 4 years ago #

    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?

  5. joaoramos
    Posted 4 years ago #

    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?

  6. sobr-rf
    Posted 4 years ago #

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

  7. joaoramos
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic