22 Responses

  1. Dave // February 8th, 2008 at 9:57 pm

    This is a great tip — many thanks! We’ve been using a really clunky workaround to make this very type of thing work.

  2. Adii // February 9th, 2008 at 12:55 am

    Micheal… Good tip, as most people customizing themes miss this rather general “workaround”. The only problem with this workaround, is that it normally screws up your Next / Prev links and that needs another workaround to make that work…

    I’ve found the easiest way to add AdSense after the second post is simply to run a little php for counter with an if statement determining when it should display the AdSense.

  3. Mike Smith // February 9th, 2008 at 2:50 am

    I was just going to post what Adii said about the next/prev links. I never got the workaround for that so I’m headed to read the link he posted now.

    This post reminded me to look into this more, so thanks for posting it :)

  4. Mike Robinson // February 9th, 2008 at 7:08 am

    My own blog has a setup like in this example, however the code behind it is different. I only call the query once then check a counter to see if it is the first post.

    counter = 0
    if counter == 0{
    first post output
    counter
    }else{
    other post output
    }

    Of course for google ads you could continue to use the counter and increase it on the output of each post, then output the google ads when the condition is met.

    My concern for the way you have done it is making two queries might have a bigger impact on performance than necessary, though it wouldn’t be too significant. :)

  5. Thássius V. // February 9th, 2008 at 8:01 am

    It took me a good time to discover this Loop feature so that I could use it on my blog. This tutorial helps a lot, thanks!

  6. Weekend Roundup #19 » JaypeeOnline // Blogging News & Reviews // February 10th, 2008 at 2:35 am

    [...] the way your posts are displayed in the index page? WPCandy’s tutorial will show you how to modify individual posts in the loop using multiple [...]

  7. Sumesh // February 10th, 2008 at 7:31 am

    Thanks for the detailed walkthrough. I am designing a new theme myself, and was searching for the featured post-ads-postheadings loop that you have mentioned. Thanks a ton!

    And I’ll remember to credit you for helping me understand the loop modifications. Hope it helps.

  8. Hafiz Rahman // February 10th, 2008 at 5:26 pm

    Offset is an interesting parameter which I haven’t ever used before. I’m really wondering about the performance (number of queries, execution time) between using simple counter within a single loop like Adii mentioned or with double loop like this.

    I’m going to test soon and report back what happened.

  9. Hafiz Rahman // February 10th, 2008 at 6:01 pm

    Okay the numbers are in.

    The double loop method results in 4 queries, while a single loop with counter costs 2 queries.

    The execution time for both is barely noticeable, both methods takes about 0.02ms to execute. But then again, this is a local test with only 1 page viewer at a time, so results in live environment might be different.

    I’m all for reducing number of queries as much as I can, and the single loop method is the way to do it.

  10. Finding Query Count for a Certain Part in a WordPress Theme | Play Work Play Studio // February 10th, 2008 at 6:39 pm

    [...] Michael Castilla’s post on modifying individual posts in the loop got me to test the query count between the double loop and single loop with counter method. This is my way to count that query count. [...]

  11. Michael Castilla // February 11th, 2008 at 6:01 am

    @Hafiz: Thanks for the feedback bro. Now we know!

  12. On Blogging Australia » Blogging tips Recently popular » WordPress Theme Editing Part 2: The Actual Coding // February 13th, 2008 at 2:55 pm

    [...] WPcandy has some neat WP PHP cheat sheets - my favourite is The Advanced WordPress Help Sheet. I heartily recommend their post on The Loop. [...]

  13. Weekend Roundup #19 - PinoyPortal // February 15th, 2008 at 6:46 pm

    [...] the way your posts are displayed in the index page? WPCandy’s tutorial will show you how to modify individual posts in the loop using multiple [...]

  14. Geek Mother // February 20th, 2008 at 9:01 am

    Hi Michael

    Well I have been here five minutes and this is the second nugget that I have discovered so far. I had seen this done on other blogs and wondered how easy it was to do and now I know!

    Thanks.

    Paul

  15. Chris // February 25th, 2008 at 7:37 am

    Featured posts - this is something I hadn’t even considered for a WordPress theme. Its an extra bonus that its also suprisingly easy!

    Thanks for opening a whole new world of theme design possibilities for me! :wink:

  16. Mastering Your WordPress Theme Hacks and Techniques // March 16th, 2008 at 8:40 pm

    [...] 1)Modifying Individual Posts In The Loop- Sometimes Clients request things like Google ads being displayed after post #2, the top post having a differently colored background, only displaying the title for a few posts. You can’t do any of this inside a single Loop, so here’s how to use multiple loops to display lists of posts differently.How to use multiple loops to display lists of posts differently. [...]

  17. links for 2008-03-23 at DeStructUred Blog // March 22nd, 2008 at 10:17 pm

    [...] WPCandy » Modifying Individual Posts In The Loop (tags: wordpress tutorial loop webdesign tips templates howto blog) [...]

  18. zinni // April 3rd, 2008 at 8:19 pm

    In my opinion I would go the counter route, as it allows you to save some request time. Depending on what type of wordpress plugins you are running, this small save in performance could make a difference. Plus you can do some cool things with the counter value like color every odd post or load special background images based on the value of the counter.

    Either way this post is definitely a great resource.

  19. Julian Johannesen // April 9th, 2008 at 9:56 pm

    This is great! Thanks so much for laying things out so clearly. I was wondering if you could say more in another post about the counter method that a few people prefer. I’d love to see a tutorial on that.

  20. paidnetpedia.com // April 12th, 2008 at 3:04 pm

    [...] 1)Modifying Individual Posts In The Loop- Sometimes Clients request things like Google ads being displayed after post #2, the top post having a differently colored background, only displaying the title for a few posts. You can’t do any of this inside a single Loop, so here’s how to use multiple loops to display lists of posts differently.How to use multiple loops to display lists of posts differently. [...]

  21. SEO & Web Design » Blog Archive » Mastering Your WordPress Theme Hacks and Techniques // May 6th, 2008 at 3:28 am

    [...] 1)Modifying Individual Posts In The Loop- Sometimes Clients request things like Google ads being displayed after post #2, the top post having a differently colored background, only displaying the title for a few posts. You can’t do any of this inside a single Loop, so here’s how to use multiple loops to display lists of posts differently.How to use multiple loops to display lists of posts differently. [...]

  22. SEO & Web Design » Blog Archive » Mastering Your WordPress Theme Hacks and Techniques // May 6th, 2008 at 3:28 am

    [...] 1)Modifying Individual Posts In The Loop- Sometimes Clients request things like Google ads being displayed after post #2, the top post having a differently colored background, only displaying the title for a few posts. You can’t do any of this inside a single Loop, so here’s how to use multiple loops to display lists of posts differently.How to use multiple loops to display lists of posts differently. [...]

Leave a reply