Thanks for visiting! This is the weblog of Lynda, a 26 year old girl living in Atlanta with her husband, three cats and two cockatiels.
| Home | Journal | Photos | Contact |
Surprisingly (to me at least) I get a lot of questions about how I insert Google Ads between my blog posts. I started doing it with Movable Type, so this method can probably be applied to just about any blog format allowing PHP and also can be applied to anything, not just a google ad. For purposes of this tiny little tutorial, I’ll tell you how to do it in EE.
First, I put my Google Adsense javascript into a separate template. This isn’t necessary of course, but if I ever need to change the colors or anything, it makes it easier to edit rather than having to go back to each page it’s added under.
Next, the page displaying the Adsense ad will need to be set to PHP Output. I’ve been told it doesn’t work with PHP Input. I frankly don’t understand why anyone uses input since it seems so horribly limited in what it can accomplish, but I guess that’s a rant for another day.
Now it’s just a matter of inserting the code.
BEFORE the {exp:weblog:entries} tag I place the following:
Directly after the {exp:weblog:entries} tag, I place this:
Change the number “2” to whatever entry you want the ad to appear under.
Finally, in order to get this to work, directly before the closing {/exp:weblog:entries} tag, place this:
So the finished product will look something like this:
<?php $googlead = 0; ?>
{exp:weblog:entries}
<?php if ($googlead == 2) { ?>
{embed="styles/inc_google"}
<?php } ?>
-- REGULAR WEBLOG CODE HERE --
<?php $googlead++; ?>
{/exp:weblog:entries}
Thank you for sharing this with me a while back. It’s easy to install and works beautifully to insert most anything (not just adsense). Now if BlogAds would just create horizontal strips.
hi Lynda
I am trying out this snippet- “Ads Between Entries” but can’t seem to get it work 100%. See my home page for what I mean. The Google ad appears 3 times though I am trying to place it under story 2 only.
Thanks
Steve
Thanks for your solution to this problem. However, I’m not sure how to set a page to php output. Could you please elaborate for a novice?
It works!
But. :( I get the following error on the page:
Notice: Undefined variable: googlead in /home/content/r/e/t/retzerj/html/Engine/core/core.functions.php(538) : eval()’d code on line 27
Any thoughts? My reading on PhP tells me that I don’t have to define variables because creating them defines them on the fly ....
John: I suppose you’ve just copied the copy above. Note there is a minor typo in Lyndas first line of code, missing the ? in front of php ... therefore, the variable isn’t initialized and you get the error you mention. It should read <?php… instead of <php…
Hi,
Got this working here - http://www.photographyblog.com - thanks!
Is it possible to adapt it to show more than one ad?
Say, one ad after entry 5 and one after entry 10?