WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple Loops Question (8 posts)

  1. Syni
    Member
    Posted 9 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 9 years ago #

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

    http://jason.goldsmith.us/archives/2004/06/23/moosecandy-120/

    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
    Member
    Posted 9 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
    Member
    Posted 9 years ago #

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

  5. Matt Mullenweg
    Troublemaker
    Posted 9 years ago #

    This section from the Codex may be helpful:

    http://codex.wordpress.org/The_Loop#Multiple_Loops

  6. Syni
    Member
    Posted 9 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
    Member
    Posted 9 years ago #

    Any other views on this topic?

  8. Matt Mullenweg
    Troublemaker
    Posted 9 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

Tags