WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] previous_posts_link() - next page re-displaying same post twice (7 posts)

  1. mjoanisse
    Member
    Posted 3 years ago #

    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!

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    <?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

  3. mjoanisse
    Member
    Posted 3 years ago #

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

    Cheers!

  4. ingvi
    Member
    Posted 3 years ago #

    Fantastic solution

    Thanks

  5. heyman
    Member
    Posted 3 years ago #

    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

  6. amdcassis
    Member
    Posted 3 years ago #

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

  7. luisfpinto
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic