The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Multiple Loops Question (8 posts)

  1. Syni
    Posted 11 years ago #

    Well, I searched but couldn't find this case. I know you can do this with MT. But here's my problem in as simple of a manner as I can explain it.

    Front page:
    Most recent post
    --- AD (or something else) ---
    Next post.

    (It seems like http://txfx.com [Tempus Fugit] has something like that, but by date)

    So how do I modify the loop to do that?

  2. Kafkaesqui

    Posted 11 years ago #

    You're just looking to place ads within The Loop? Check out this plugin:


    A do it yourself method would involve setting up your own variable to count off posts, which you test to determine when to display the ad. For example, at the start of the Loop:

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

    Insert your variable with the auto-increment operator (++):

    <?php if (have_posts()) : while (have_posts()) : the_post(); $post_num++; ?>

    Then right after this line place:

    <?php if(2 == $post_num) : ?>
    ~ your ad code goes here ~
    <?php endif; ?>

    This will insert the ad before the second (2) post.

  3. Syni
    Posted 11 years ago #

    Great thanks. I also wanted to see if I could style the 1st post and the rest of them differently, so that do it yourself method looks best to me. Really appreciate the help!

  4. DianeV
    Posted 11 years ago #

    Tasty, Kafkaesqui. That's just what I needed too. Much thanks.

  5. Matt Mullenweg
    Posted 11 years ago #

    This section from the Codex may be helpful:


  6. Syni
    Posted 11 years ago #

    Thanks Matt, although I wanted a more specific answer which is why I asked the quesiton. I stared at that page for at least a half an hour and really didn't pull anything out of it other than the fact that I can use the rewind_loop() function (should that be in the top example as well?) like it doesn't say anything about how to start the 2nd loop at the 2nd post and use the first loop to display only the most recent post or date.

  7. Syni
    Posted 11 years ago #

    Any other views on this topic?

  8. Matt Mullenweg
    Posted 11 years ago #

    Basically you have to manipulate the query string that's passed to the loop function as you would in the address URI. Try experimenting with different arguments in after index.php and you should be able to find the proper combo you need for query posts.

Topic Closed

This topic has been closed to new replies.

About this Topic