WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] previous_posts_link() – next page re-displaying same post twice

[Resolved] previous_posts_link() – next page re-displaying same post twice

  • Hi there,
    the issue i’m experiencing has to do with the previous_posts_link() function.

    <?php
    #####################
    ## NEWS & VIEWS    ##
    #####################
    if (is_page(59)) { ?>
        <h1><?php the_title(); //News & Views ?></h1>
    
    	<?php query_posts('cat=5&posts_per_page=2'); ?>
        <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
    
                        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                        <?php edit_post_link('&uarr;&darr; Edit', '<span class="edit">', '</span>'); ?>
                        <div class="posts">
                        <?php the_excerpt(); ?>
                        </div>
    
        <?php endwhile; else: ?>
        <?php endif; ?>
    
        <?php previous_posts_link(); ?>
        <?php next_posts_link(); ?>

    The link(s) for ‘next’ and ‘previous’ posts are displaying correctly, problem i have is when clicking through to page 2, the first post is being re-displayed..

    Any ideas as to why this could occur?
    Thanks..
    CHEERS!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    @alchymyth

    Forum Moderator

    <?php query_posts('cat=5&posts_per_page=2'); ?>

    try to expand the code by including the paged parameter:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=5&posts_per_page=2&paged=' . $paged); ?>

    http://codex.wordpress.org/Function_Reference/query_posts#Pagination_Parameters

    ! perfect. Thank you so much, very much appreciated! (Will read more about)

    Cheers!

    Fantastic solution

    Thanks

    I have the same problem. This my code:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('post_type=portfolio&posts_per_page=9&paged=' . $paged);
    ?>

    The link(s) for ‘next’ and ‘previous’ posts are displaying correctly, problem i have is when clicking through to page 2, the first post is being re-displayed..

    This url shows up:
    http://www.heymansmulders.nl/wordpress/?paged=2

    But is should be:
    http://www.heymansmulders.nl/wordpress/?page_id=743&paged=2

    I have set this page as my front page.
    When this page is NOT my frontpage it all works fine.

    Any Idea’s?
    Heyman

    Had to say thanks to alchymyth, was getting on my nerves and then it worked like a charm ! 🙂

    I justed wanted to thank you guys and post here my problem and how it was resolved with your help. Maybe it will be useful to someone else.

    My previous_post_link() was not working because of the following query_posts:

    <?php query_posts('posts_per_page=2'); if (have_posts()) : ?>

    So I used your fix:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      query_posts('posts_per_page=2&paged=' . $paged); if (have_posts()) : ?>

    And now it works perfectly. Thanks again.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] previous_posts_link() – next page re-displaying same post twice’ is closed to new replies.
Skip to toolbar