WordPress.org

Ready to get started?Download WordPress

Forums

Exclude most recent post in 2nd loop (8 posts)

  1. Adapt-a-put
    Member
    Posted 8 years ago #

    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?

  2. moshu
    Member
    Posted 8 years ago #

  3. Adapt-a-put
    Member
    Posted 8 years ago #

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

  4. moshu
    Member
    Posted 8 years ago #

    => 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/

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

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

  6. Adapt-a-put
    Member
    Posted 8 years ago #

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

    Thanks!

  7. Adapt-a-put
    Member
    Posted 8 years ago #

    @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.

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic