WordPress.org

Support

Support » How-To and Troubleshooting » Exclude most recent post in 2nd loop

Exclude most recent post in 2nd loop

  • I have 2 loops on my index page. The first loop displays the most recent post.

    <?php query_posts('posts_per_page=1'); ?>

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <!-- bla bla bla -->

    <?php endwhile; ?>

    <?php else : ?>

    <?php endif; ?>

    The second loop must show the other 5 recent posts/the posts except the one above from loop1.
    This is the 2nd loop:

    <?php rewind_posts(); ?>

    <?php
    if ($posts) : foreach ($posts as $post) : start_wp();
    ?>

    <?php if (get_posts('')) { ?>

    <!-- bla bla bla -->

    <?php } ?>

    <?php endforeach; else: ?>

    <?php endif; ?>

    How do I alter my second loop so that the most recent post is excluded and only 5 posts are shown?

Viewing 7 replies - 1 through 7 (of 7 total)
  • http://wordpress.org/support/topic/28203?replies=15
    => if I use queries it will screw the whole thing

    wordpress.org/support/topic/35504?replies=23
    => I wonder who that last user is…

    => if I use queries it will screw the whole thing

    That’s not necessarily the fault of the code.
    As you might have seen there, I asked a very similar question, got an answer, took the code from there and it works perfectly:
    http://myprairiegazette.transycan.net/

    Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    I’m not certain I understand why you want two different loops here. You’re basically wanting to display the first 6 posts, but display the first one differently than the other five. So making two loops like this just seems like a weird thing to do, causing unnecessary overhead and such.

    Why not pull the first six posts, display the first one manually, then loop for the remaining 5?

    <?php
    query_posts('posts_per_page=6');
    if (have_posts()) {
    // do first post
    the_post();
    <!-- bla bla for first post -->
    while (have_posts()) {
    the_post();
    ?>
    <!-- bla bla bla for rest of the posts-->
    <?php
    } // endwhile
    } // endif
    ?>

    @moshu:
    OK, it works now. I tried your suggestion and built the whole thing up from scratch.

    Thanks!

    @otto42:

    I wanted something like this:

    ———————
    | first full post |
    ———————

    ———————
    | sidebar-y stuff |
    | in between |
    ———————

    ———————
    | excerpts of 5 |
    | most recent posts |
    ———————

    If it works the same way with your suggestion, then I’m just plain stupid.

    Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    Adapt-a-put: Well, it *can* work the same way with my suggestion.

    Up where I say this bit:
    <!-- bla bla for first post -->
    while (have_posts()) {

    Just put your “sidebary stuff” in between those two lines.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Exclude most recent post in 2nd loop’ is closed to new replies.