WordPress.org

Ready to get started?Download WordPress

Forums

[closed] next_posts_link showing same posts as Page 1 (15 posts)

  1. deniseyap
    Member
    Posted 10 months ago #

    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:

    <?php
    /*
    Template Name: News
    */
    ?>
    <?php get_header(); ?>
    <style type="text/css">
    #phogallery .post ul li {
    color: #b30838;
    font-weight: normal;
    }
    </style>
    
    <div id="phogallery">
    <?php get_sidebar(); ?>
    
    <div class="post">
    
    <ul>
    <li>latest news</li>
    </ul>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    
    <?php
    $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(); ?>
    <ul>
    <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>
    </ul>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <?php endwhile; ?>
    <?php
    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 />
    </div>
    </div> 
    
    <?php get_footer(); ?>
  2. vtxyzzy
    Member
    Posted 10 months ago #

    Try removing the quotes around $paged here: 'paged' => '$paged'

  3. pupilo
    Member
    Posted 3 months ago #

    Hi. I have a similar problem.

    <div id="portafolio">	
    
    				<?php
    
    		$args = array(
    
    			'post_type' => 'post',
    			'posts_per_page' => 8,
    			 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
    
    			 );
    
    		query_posts($args);
    
    		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>
    		</div><!--//home_box_belowTxt-->
    	</div><!--//home_box_below-->
    </div><!--//posts_below-->
    		<?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>
    
    		</div><!--//blog_nav_cont-->
    
    <?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.

  4. vtxyzzy
    Member
    Posted 3 months ago #

    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

  5. pupilo
    Member
    Posted 3 months ago #

    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.
    :/

  6. vtxyzzy
    Member
    Posted 3 months ago #

    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.

  7. vtxyzzy
    Member
    Posted 3 months ago #

    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
    
        );
  8. pupilo
    Member
    Posted 3 months ago #

    It seems it stays on page 1, but the url displays .../page/2/
    here's the link if you want to take a look.
    blog.pupilo.com.mx/cont/

  9. vtxyzzy
    Member
    Posted 3 months ago #

    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.

  10. pupilo
    Member
    Posted 3 months ago #

    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)

  11. Evan Herman
    Member
    Posted 3 months ago #

    Make sure your 'Settings > Reading' matches the 'posts_per_page' in your query

  12. vtxyzzy
    Member
    Posted 3 months ago #

    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.

  13. pupilo
    Member
    Posted 3 months ago #

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

  14. Evan Herman
    Member
    Posted 3 months ago #

    Thread hijack ftw!

  15. esmi
    Forum Moderator
    Posted 3 months ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic