I've been playing with the Better Feed WordPress plugin to insert ads in my RSS feed. As I mentioned previously, it's fairly easy to add a text footer or graphics ad into your feed. However, if you want to rotate between multiple ads, then you need to hack the plugin. Read on to find out how.
You will need to find the following line in the Better Feed plugin (if you have not added a footer or modified the plugin, it's around line #101):
$content .= wp_ozh_betterfeed_detokenize($wp_ozh_betterfeed['footer']);
I'm going to call it the "footer" line. Once you have found the "footer" line, you will need to add a block of code above that line. Something like:
[block of code]
$content .= wp_ozh_betterfeed_detokenize($wp_ozh_betterfeed['footer']);
I have put together three sets of block codes that you can use. Select the one that best suits your needs.
Block 1 – Alternate ads
This code block is for alternating ads in your feed. For instance, post #1 will show "Ad-B", post #2 will show "Ad-A", post #3 will show "Ad-B" again, post #4 will show "Ad-A" again, etc. Here's the block to insert above the "footer" line:
if ($id % 2 == 0 ) {
$ad = "Ad-A";
} else {
$ad = "Ad-B";
}
$content .= $ad;
Block 2a – Rotate between four ads
[2007.03.10 note: The random number generator used in this block can cause old posts to show up as "updated" in Bloglines. If you don't want this to happen, use Block 2b instead.]
This code block is for displaying one of four ads in your feed. For instance, post #1 will show either "Ad-C" or "Ad-D", post #2 will show either "Ad-A" or "Ad-B", post #3 will show either "Ad-C" or "Ad-D" again, post #4 will show either "Ad-A" or "Ad-B" again, etc. Here's the block to insert above the "footer" line:
if ($id % 2 == 0) {
$num = rand(1,2);
if ($num == 1) {
$ad = "Ad-A";
} else {
$ad = "Ad-B";
}
} else {
$num = rand(1,2);
if ($num == 1) {
$ad = "Ad-C";
} else {
$ad = "Ad-D";
}
}
$content .= $ad;
Block 2b – Rotate between four ads
[Added on 2007.03.10]
This code block is for displaying one of four ads. It's like the block of code above, but it uses the timestamp of the post instead of a random number generator. It shouldn't change an old post to "updated" in Bloglines. Here's the block to insert above the "footer" line:
$num = get_post_time('s');
if ($id % 2 == 0) {
if ($num < 30) {
$ad = "Ad-A";
} else {
$ad = "Ad-B";
}
} else {
if ($num < 30) {
$ad = "Ad-C";
} else {
$ad = "Ad-D";
}
}
$content .= $ad;
Block 3 – Display an ad for every 3rd, 6th, and 9th post
I use this code block for my news site. I write over 20 posts a day on that site and it would look too commercial if I ran a RSS ad in every post. This block of code will display an ad for every 3rd, 6th, and 9th post. Here's the block to insert above the "footer" line:
$ad3 = "Ad-A";
$ad6 = "Ad-B";
$ad9 = "Ad-C";
$num = substr ($id, -1);
switch ($num)
{
case 3:
$content .= $ad3;
break;
case 6:
$content .= $ad6;
break;
case 9:
$content .= $ad9;
break;
}
You will need to replace "Ad-A", "Ad-B", "Ad-C", and "Ad-D" with the html code for your ads. Keep in mind that the code is already using double quotes. So, you will either need to use single quotes or omit the quotes in your html code for your ads. For instance:
$ad = "<p align=center><a href=http://www.embeddedstar.com/careers/><img src=http://edageek.com/adimages/jobs468.gif border=0></a></p>";
As you can see, I didn't use any quotes between the double quotes above.
One other note. WordPress assigns post id numbers in the order you saved them. The id numbers can get out of order if you don't publish your posts in the same order you saved them. This may cause the ads to appear to display out of sequence (ie – the same ad displaying two times in a roll). That is not the case.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Free Magazines : : Find a Job : : iZachy : : Daddy Forever : : Embedded Star : : EDA Geek : : EDA Blog : : FPGA Blog
© 2007 Online Destiny Ltd : : iZachy is a trademark of Online Destiny Ltd