Support » How-To and Troubleshooting » next_posts_link showing same posts as Page 1

next_posts_link showing same posts as Page 1

  • Hiya,

    I’ve been having some trouble with pagination.

    I use a Page-template to display 10 posts per page from 1 particular category. Everything is working fine, except that when I click on “Older Entries”, the page refreshes to /news/page/2, but the posts that are on the page are exactly the same posts as the ones one /news (i.e. page 1).

    I have been troubled by this for days, read a lot of the codex and other posts on the topic, but I simply cannot figure it out!

    If it’s important at all my permalinks are set to /%postname%/. Any help or pointing in the right direction is WONDERFULLY APPRECIATED!

    Please tell me it’s not an error with a missing semi-colon…

    Here is my code:

    Template Name: News
    <?php get_header(); ?>
    <style type="text/css">
    #phogallery .post ul li {
    color: #b30838;
    font-weight: normal;
    <div id="phogallery">
    <?php get_sidebar(); ?>
    <div class="post">
    <li>latest news</li>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    $args = array(
    	'cat' => '66',
    	'orderby' => 'date',
    	'order' => 'DESC',
    	'posts_per_page' => '10',
    	'paged' => '$paged'
    query_posts( $args ); ?>
    <?php if ( have_posts() ) : while (have_posts() ) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><pre><?php the_title() ;?></pre></a></li>
    <li><a href="<?php the_permalink() ?>"> <?php the_post_thumbnail(array (580, 580)); ?></a></li>
    <li><?php the_excerpt(); ?></li>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <?php endwhile; ?>
    next_posts_link( 'Older Entries', $post->max_num_pages );
    previous_posts_link( 'Newer Entries', $post->max_num_pages ); ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <?php get_footer(); ?>
Viewing 14 replies - 1 through 14 (of 14 total)
  • Try removing the quotes around $paged here: ‘paged’ => ‘$paged’

    Hi. I have a similar problem.

    <div id="portafolio">	
    		$args = array(
    			'post_type' => 'post',
    			'posts_per_page' => 8,
    			 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
    		while (have_posts()) : the_post(); ?>                        		
    <div id="posts_below">
    			<div class="home_box_below" onclick="window.location='<?php the_permalink(); ?>'; return false;">
    				<?php the_post_thumbnail('feat-image'); ?>
    		<div class="home_box_belowTxt">
    				<h3><?php the_title(); ?></h3>
    				<div class="categorias"><?php the_category(', ') ?></div>
    		<?php endwhile; ?>  	
    		<div class="nav_cont">
    			<div class="left"><?php previous_posts_link('Siguiente') ?></div>
    			<div class="right"><?php next_posts_link('Anterior') ?></div>
    			<div class="clear"></div>
    <?php wp_reset_query(); ?>
    	<div class="clear"></div>
    <?php get_footer(); ?>

    The links to the next page do redirect me to the next page but the same results are displayed.
    I have the same code in a diferent page (with other restrictions) and it works just fine, but this one I don’t seem to find the error in the code. Perhaps someone could help me. Thanks.

    The expression you show for setting ‘paged’ is missing a closing parenthesis just before the question mark:

    'paged' => ( get_query_var('paged') ) ? get_query_var('paged') : 1)

    If that does not fix the problem, try this:

    'paged' => ( get_query_var('paged')) ? get_query_var('paged') : ((get_query_var('page')) ? get_query_var('page') : 1 )

    The ‘paged’ variable is not set on static front pages. See the explanation here: http://codex.wordpress.org/Function_Reference/get_query_var

    It did’t work, either one. Well, with the first one I got an error message something like: “an extra ‘)’ was found” something like that. And with the other one I got the same problem as before. It displays the same post on page 1, 2, 3, and on.

    Sorry, on the first one I had an extra paren. Please try this:

    'paged' => ( get_query_var('paged') ) ? get_query_var('paged') : 1

    EDIT: that is not correct either. I will try again in a bit.

    OK, this should show the value of the $paged variable to see if it is being set properly:

    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    else { $paged = 1; }
    print_r("<pre>PAGED: $paged</pre>");
    $args = array(
       'post_type' => 'post',
       'posts_per_page' => 8,
        'paged' => $paged

    It seems it stays on page 1, but the url displays …/page/2/
    here’s the link if you want to take a look.

    Do you have any other queries in the template before the one you showed? If so, try using wp_reset_query() after you are finished with that query.

    I placed it just before this query and now it works! It must other query that’s causing the trouble and for now it does work placing it just before it. So thank’s… thank you very much! 🙂

    (I’ll try to see If I can find the one that’s causing the trouble)

    Make sure your ‘Settings > Reading’ matches the ‘posts_per_page’ in your query

    If your problem has been solved, please use the dropdown on the right to mark this topic ‘Resolved’ so that anyone else with a similar question can see that there is a solution.

    Ouch, I did not started this topic so I cannot change its status :/
    I think deniseyap may be the one who can close it.

    Thread hijack ftw!



    Forum Moderator

    I am now closing this 7 month old topic as it references an older version of WordPress.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘next_posts_link showing same posts as Page 1’ is closed to new replies.
Skip to toolbar