• Resolved jrickards

    (@jrickards)


    On my home page, I used the code from bottom of The Loop page and ended up with the correct result whereby the first item is different from the remaining 9. However, I would like to change that so that the first 3 items receive the same treatment but I can’t figure out how to change the code. I tried changing showpost=1 to showpost=3 but it didn’t work right in the second section. I think the code if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> has to be changed to a while or other loop so that it may repeat but I am not entirely certain.

    I would appreciate any help I can get.

    TIA,

    Jules

Viewing 3 replies - 1 through 3 (of 3 total)
  • Your problem is the code “from bottom of The Loop page,” which is designed to test on the first post ID. Extending it to three posts sort of defeats that.

    Since you’re not doing anything but changing the layout of your posts after the third one, drop query_posts() and use this as your loop code:

    <?php
    $count = 3; // # of post in 'current posts' format.

    while(have_posts()) : the_post(); $postcount++;
    if( $count >= $postcount ) :
    ?>

    ~ Current posts format ~

    <?php else : ?>

    ~ Previous posts format ~

    <?php endif; endwhile; ?>

    Thread Starter jrickards

    (@jrickards)

    Perfect! Thanks.

    Might this also be a better format for this loop because it is more flexible?

    It’s better in a couple ways:

    1. It is a more flexible method.

    2. You’re not dealing with the (admittedly slight) overhead of separate post queries.

    Just keep in mind (noting to future readers…) that it works when the only difference between the first N posts and the latter ‘previous’ ones on your page is simply one of layout or design.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Need help with The Loop’ is closed to new replies.