• Hi folks,

    There’s a lot of posts on this subject, however, none of them seem to solve my problem. I’ve made a few page templates that access the post loop (not pages) outside of the main loop.php file.

    The problem is that, upon navigating to the next page, the same posts are being shown.

    Here’s my code, in full, for this area:

    <div class="container_12">
    	<div class="events-landing-rest-container">
    
    <?php
    		 $args = array(
    					   'cat' => '8',
    					   'post_type' => 'post',
    					   'posts_per_page' => 6,
    					   'offset' => 1,
    					   'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
    					   );
    
    		query_posts($args);
    
    	while (have_posts()) : the_post(); ?>
    
    	<div class="prefix_1 grid_5 events-landing-rest">
    
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<?php if ( has_post_thumbnail() ) { ?>
    			<a class="post-featured-image" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
    				 <?php the_post_thumbnail(); ?>
    			</a>
    			<?php } ?>
    
    			<header>
                    <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'starkers' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
                    <?php starkers_posted_on(); ?>
                </header>
    
    <?php the_excerpt(); ?>
    
                <footer>
    
                    <p><?php if ( count( get_the_category() ) ) : ?>
                            <?php printf( __( '%2$s', 'starkers' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?> |
                    <?php endif; ?>
                    <?php comments_popup_link( __( 'Leave a comment', 'starkers' ), __( '1 Comment', 'starkers' ), __( '% Comments', 'starkers' ) ); ?></p>
    
    				<div class="social-sharing">
    					<a class="ss-facebook" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>">Share on Facebook</a>
    					<a class="ss-twitter" href="https://twitter.com/share?&text=<?php the_title(); ?>&nbsp;via%20@Corridor8&url=<?php the_permalink(); ?>">Share on Twitter</a>
    				</div>
    
                </footer>
    		</article>
    
    </div>
    
    <?php endwhile; // End the loop. Whew. ?>
    
    </div></div>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    	<div class="container_12">
    	<div class="prefix_1 grid_11">
        	<nav class="prev-next-container">
    	        <span class="newer-posts"><?php previous_posts_link( __( '&larr; Newer events', 'starkers' ) ); ?></span>
    			<span class="older-posts"><?php next_posts_link( __( 'Older events &rarr; ', 'starkers' ) ); ?></span>
    	    </nav>
    	</div>
    	</div>
    <?php wp_reset_query();?>

    Thanks,
    Richard

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    	'cat' => '8',
    	'post_type' => 'post',
    	'posts_per_page' => 6,
    	'offset' => 1,
    	'paged' => $paged,
    );

    Thread Starter richgcook

    (@richgcook)

    Hi @esmi – same issue occurs.

    You can see the page I’m working on here:

    http://richgc.com/dust/c8/events/

    There’s two loops on this page, so maybe that’s why?

    Full code for page:

    <div class="container_12 events-landing-first-post-container">
    
    	<?php query_posts("posts_per_page=1&cat=8"); while ( have_posts() ) : the_post(); ?>
    	<div class="prefix_6 grid_6">
    		<div class="events-landing-first-post">
    		<h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a></h3>
    		<?php //starkers_posted_on(); ?>
    		<?php the_excerpt(); ?>
    		<footer>
    
    			<div class="social-sharing">
    				<a class="ss-facebook" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>">Share on Facebook</a>
    				<a class="ss-twitter" href="https://twitter.com/share?&text=<?php the_title(); ?>&nbsp;via%20@Corridor8&url=<?php the_permalink(); ?>">Share on Twitter</a>
    			</div>
    
            </footer>
    		</div>
    	</div>
    	<?php endwhile; ?><?php wp_reset_query();?>
    
    </div>
    
    <div class="container_12">
    	<div class="events-landing-rest-container">
    
    <?php
    		 $args = array(
    					   'cat' => '8',
    					   'post_type' => 'post',
    					   'posts_per_page' => 6,
    					   'offset' => 1,
    					   'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
    					   );
    
    		query_posts($args);
    
    	while (have_posts()) : the_post(); ?>
    
    	<div class="prefix_1 grid_5 events-landing-rest">
    
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<?php if ( has_post_thumbnail() ) { ?>
    			<a class="post-featured-image" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
    				 <?php the_post_thumbnail(); ?>
    			</a>
    			<?php } ?>
    
    			<header>
                    <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'starkers' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
                    <?php starkers_posted_on(); ?>
                </header>
    
    <?php the_excerpt(); ?>
    
                <footer>
    
                    <p><?php if ( count( get_the_category() ) ) : ?>
                            <?php printf( __( '%2$s', 'starkers' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?> |
                    <?php endif; ?>
                    <?php comments_popup_link( __( 'Leave a comment', 'starkers' ), __( '1 Comment', 'starkers' ), __( '% Comments', 'starkers' ) ); ?></p>
    
    				<div class="social-sharing">
    					<a class="ss-facebook" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>">Share on Facebook</a>
    					<a class="ss-twitter" href="https://twitter.com/share?&text=<?php the_title(); ?>&nbsp;via%20@Corridor8&url=<?php the_permalink(); ?>">Share on Twitter</a>
    				</div>
    
                </footer>
    		</article>
    
    </div>
    
    <?php endwhile; // End the loop. Whew. ?>
    
    </div></div>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    	<div class="container_12">
    	<div class="prefix_1 grid_11">
        	<nav class="prev-next-container">
    	        <span class="newer-posts"><?php previous_posts_link( __( '&larr; Newer events', 'starkers' ) ); ?></span>
    			<span class="older-posts"><?php next_posts_link( __( 'Older events &rarr; ', 'starkers' ) ); ?></span>
    	    </nav>
    	</div>
    	</div>
    <?php wp_reset_query();?>

    Well, you’re only going to get pagination on one of those Loops. Not for both. But I’d suggest you amend the arguments in the second query as well.

    Oh – and use http://codex.wordpress.org/Function_Reference/WP_Query for the Loop that is deemed to be “secondary”. query_posts() should only ever be used for customising the primary (main) Loop in a template file.

    Thread Starter richgcook

    (@richgcook)

    Hi @esmi, thanks for your help. I changed both queries to the structure you suggested, but it’s still causing the same problem. The top query doesn’t need pagination… it’s only pulling in one post, which is the latest post, that’s why the rest are offset. Any ideas? Many thanks for your help.

    Change the top loop to use WP_Query() and see if that helps.

    Thread Starter richgcook

    (@richgcook)

    Hi @esmi… I’m at work now so can’t do this straight away, but I never tried just removing the whole top loop to see if it was causing problems and the same issues occured.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Same posts being displayed on next page (pagination)’ is closed to new replies.