ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Post ads every few blog posts?

October 24, 2008 3:16pm

Subscribe [3]
  • #1 / Oct 24, 2008 3:16pm

    nomi

    18 posts

    I’ve got a blog area of the site that has a blog listing with the summaries of each article. What I’d like to do, is have an ad show after every 2 posts or so, like Engadget.

    I’m running into a blank on how to do this. Should I look into using conditionals or do I need to run a query? Any tips?

    Thanks!!

  • #2 / Oct 24, 2008 6:02pm

    Boyink!

    5011 posts

    I’d experiment with conditionals and looking at the count variable.

  • #3 / Oct 24, 2008 6:06pm

    nomi

    18 posts

    Awesome, thanks for the hint. I’ll investigate it and post my results. Thanks!

  • #4 / Oct 24, 2008 6:26pm

    winslow4

    7 posts

    Using php and setting the PHP Parsing Stage to output. You can accomplish what you want.

    {exp:weblog:entries weblog="{master_weblog}"}
        {count}
            <?php
                if( '{count}' %2 == 0) {
            ?>
                    Display ad
            <?
            }
            ?>
    {/exp:weblog:entries}
  • #5 / Oct 24, 2008 6:58pm

    nomi

    18 posts

    Ok, you guys rock. Thanks very much for saving me half the day. Between Micheal’s hint and winslow4’s code, I got this working:

    {exp:weblog:entries weblog="{master_weblog}"
    {if count=='2'}
    ---Ad code here---
    {/if} 
    {/exp:weblog:entries}

    Pretty simple, but it would have taken me a year to figure out alone!

  • #6 / Oct 24, 2008 7:11pm

    Mark Bowen

    12637 posts

    Just as a quick note. With the code you have above you will only get the advert appearing once on each page which didn’t sound like what you asked for originally?

    If you need an advert every two posts so if you had say 8 posts on a page you would end up with four or so adverts then you would need something like winslow4’s code to do this in the easiest way.

    If of course you do just want an advert in place of the second post then your code will work. Note though that placing an :

    {if count == "2"}
    ---Ad code here---
    {/if}

    code block inside a weblog tag will mean that whatever your second post content is won’t be shown unless you place it within the code block too.

    Best wishes,

    Mark

  • #7 / Oct 24, 2008 7:15pm

    nomi

    18 posts

    Thanks, Mark. Um yeah, I just figured that out. Duh!

    Ok, I tried winslow4’s code originally, but it was showing underneath every entry instead of just every two. Going back again!

  • #8 / Oct 24, 2008 7:19pm

    Mark Bowen

    12637 posts

    Oops sorry just noticed I posted something a little wrong above. Was writing too quickly. I meant that it will show up for the second post but not every second post.

    Sorry all other code would still show but not repeat is what I meant. PHP is really the only easy way to do this. I really should make a plugin for this kind of thing one day.

    Best wishes,

    Mark

  • #9 / Oct 24, 2008 7:20pm

    nomi

    18 posts

    Ok, winslow4’s code does work after all. I forgot to enable php on the template. Weekend time for me, brain is absent. All good now. Thank you again winslow4 and Micheal and Mark.

  • #10 / Oct 24, 2008 7:22pm

    Mark Bowen

    12637 posts

    Well thanks should just go to Michael and winslow4. I just wanted to let you know in case that is what you wanted. Have done this many times before and I really should make a plugin for this kind of thing one day soon.

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases