Time Delayed Blog Ads On Your Post

I like a clean blog layout. I'm pretty much anal about it. So naturally it would be hardpressed for me to start machine gunning my blog with ads like a lot of blogs out there. After all, as anyone who earned more than a buck from it would tell you that it's about where you place it rather than how much is on in the first place.

I got the idea from Micheal who is also the creator of the awesome Bad Behavior spam filter. What he's done and what I followed suit is to place the least amount of ads on our blog for a certain period of time. After that time, the ads will come out.

It's good for those of us who don't want a cluttered single post and always tend to refer people back to our old posts to read. Since I've been getting quite a few people that have asked me how I did it, I thought I might explain it in greater detail here. What you do is basically ad this to your single post template:

<?php $days_since = floor((date('U') - get_the_time('U')) / 86400); if($days_since > 7) : ?>
"Insert ad code here"
<?php endif; ?>

*Note: To deal with the automatic smiley conversion, I put a space between ":" and "?". Just remove the space if you copied the entire code from here.

Now, you can pretty much guess that I'm running WordPress for this, but on the upside this works for all blogs that run on PHP and it's pretty flexible too.

One is that while my ads are set to come out on my single posts after 7 days, you can set it to come out whenever you want or even disappear after a set amount of days. All you have to do is edit the number "$days_since > 7″ to whatever day you want. Altering the ">" to "<" will set it to days earlier than the set amount of days so whatever you put will only come out for those few days.

The other thing here is that whatever you insert in between the code doesn't necessarily have to be ads, it can be anything you want. Other text, javascript...etc. The possibilities are only limited to your imgination. But in this case, I use it for my adsense and it works like a charm. You can see it in action on my blog if you compare any recent posts to posts later than 7 days.

So there you have it. I hope you can put it to good flexible use. Maybe even develop a WordPress plugin from it, who knows? If you do have any problems though. Let me know and we'll see what we can do with it.

0 Trackback and Pingbacks: »

5 People Said A Couple Of Things: »