WordPress.org

Forums

Next_Posts_Link not displays same posts (not next posts) when using Offset. (3 posts)

  1. Leroy00
    Member
    Posted 4 years ago #

    Hi Guys,

    I'm editing the Main Index Template to give my site more of a magazine feel. I have 2 sections on the page that display featured stories and the 3 newest stories, both using the get_posts() query.

    I've now laid out the remaining section, which uses the main wordpress loop. Due to the fact that I've already displayed 3 of the newest stories I do not want to display them again when the main loop runs, so I've been trying to use offset to achieve this.

    The problem is that when I use offset the correct number of posts are skipped, but when I click the Next_Posts_Link the same posts are diplayed again on page 2, which should display the remaining posts.

    I've tried the following to resolve this problem:

    1)
    query_posts('posts_per_page=6&offset=3');

    The offset works, but the same four posts are displayed on page 2.

    2)
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'offset'=>3,
    'posts_per_page'=>6,
    'caller_get_posts'=>1,
    'paged'=>$paged,
    );
    query_posts($args);
    ?>

    Again, the offset works, but the same four posts are displayed on page 2.

    3) I've tried creating a new WP_Query() object and referencing this in the loop, with the same results.

    In all three cases, if I remove the offset parameter, when clicking the Next_Posts_Link the correct posts are displayed... all bar the three that I'm trying to skip.

    If anyone could help, I'd be really grateful.

    Thanks!

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    offset does not work together with pagination (full stop)

    to avoid the same posts being shown again, try and use the $do_not_duplicate method described in http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

  3. Leroy00
    Member
    Posted 4 years ago #

    Hi alchymyth,

    I've started testing this and it appears to be the solution that I'm looking for; thanks for the quick response :)

Topic Closed

This topic has been closed to new replies.

About this Topic