I'm building a Drupal 6.0 site and I wanted to try adding in an ad between the 2nd and 3rd posts, etc on the front page but couldn't find a ready-made Drupal snippet to use.
Wordpress does this - it's a little bitof code you add to their "loop" that runs like this:
// Set Counter to 1, First Post
$counter = 1;
if (have_posts()) :
while (have_posts()) :
$counter = $counter + 1;
the_post();
the_content();
if(2 == $counter)
{
echo ‘Adsense code’;
}
endwhile;
endif;
I think we can replicate this in Drupal quite easily but my PHP-fu is quite rusty (and was never that good to start off with). Before I hit the php site to re-educate myself I wonder if this is something someone here at the forums can solve quite easily.
For starters I imagine we'll want to take out "print $content" on whatever page(s) we're going to do this on and replace it with a call to pull nodes so that we can add something to that call. Then I don't know the best way to do the counting thing in Drupal. Would a "while" loop like Wordpress does work or would it make more sense to do somekind of foreach () if / else statement?
Any ideas? Thanks in advance :) (and I'll work on this week if I don't see an answer here - would post it of course)
Comments
Same interest
I had the same Idea. Now I manage that with a separate kind of node every 5 posts, but this only works for the frontpage. I requested this feature in Adsense.
Oceria doesn't know where this -repeatbutton -repeatbutton is....
Try this worked for me on drupal 6.x
http://urlgreyhot.com/personal/weblog/drupal_tip_2_sprinkling_ads_throug...