Home/ Journal Bens Projects Binary Moon Archives About Ben Gillbanks Subscribe to Binary Moon Updates

Subscribe to Binary Moon Website Updates, it's Free and Easy to Stay in Touch

Search Binary Moon

Search Binary Moon

How to Optimise : Time based Adsense

In my Adsense tips post the other day I mentioned time based ads, and how I like to display ads based on the age of the article they are on - I should probably point out that I only use this technique on single posts, and not on the site at large.

I really like this idea for a number of reasons:

  • It stops regular visitors from being snowed under with ads
  • It means I don't have to see the adverts
  • It gives search engine visitors (who will likely end up at older posts) the advertising - and I feel they are more likely to click adverts

So how do I do this? It's actually incredibly simple indeed (I hope). All I do is use the WordPress command get_the_time('U') to get the time the article was made. I then calculate what the time was x amount of days ago and compare that with the age of the article (to work out what age bracket the article falls in). I then place this code inside my "wordpress loop".

<?php
// get the time of the current post
$u_time = get_the_time('U');
// reset my selector
$tooOld = 0;
// set the time selector
if ( ( time() - 1209600 ) >= $u_time ) { $tooOld = 1; } // 60*60*24*14 = 1209600 = 14 days
if ( ( time() - 15552000 ) >= $u_time ) { $tooOld = 2; } // 60*60*24*30*6 = 15552000 = 6 months
?>

Once I have the age of the article I look at inserting my adverts in whatever positions I think are best. For this I use the following code - again keeping it very simple.

<?php if( $tooOld > 0 ) { ?>
INSERT AD CODE HERE FOR POSTS 14 DAYS AND OLDER
<?php } ?>

<?php if( $tooOld > 1 ) { ?>
INSERT AD CODE HERE FOR POSTS 6 MONTHS AND OLDER
<?php } ?>

Something else I like to do is show different sized adverts in different categories so you can combine the two like so...

<?php if( $tooOld > 0 && in_category( 1 ) ) { ?>
INSERT AD CODE HERE FOR POSTS 14 DAYS AND OLDER AND ARE IN CATEGORY 1
<?php } ?>

Hiding Adverts

Something I have recently started using on Binary Joy is an additional little feature which lets me hide the adverts on certain posts. I find this helpful on site news posts, such as competition announcements, on which I don't want ads to appear. To do this I add a custom field to the post saying to hide the adverts. You can call the it whatever you like but I have chosen display_ads as the field name. All you have to do to make use of it is add an extra 'if' statement after your age checking code.

// get the ad display properties
if( get_post_meta( $post->ID, "display_ads", true ) == "" ) { tooOld = -1; }

I set the $tooOld status to -1 so that I can use the value of 0 for other things - for example on Binary Joy I always show adverts (unless tooOld == -1), but I replace them with bigger and bigger ads as the value increases - so 0 is the smallest size.

In action

The best place to see me using this system is Binary Joy - my gaming site. Check out posts of different ages (in the archives) and you should be able to see the different positions available.

I think it's a system that works really well and, as I said before, my adsense earnings are increasing - so it can't be that bad an idea (I hope). I'd love to hear your opinions.

13 Responses to “How to Optimise : Time based Adsense” Leave a reply ›

  • This is an idea that I'd like to experiment with. However, I not much of a code jockey and can barely tell PHP from PSP. Where would you insert the above code in your template?

    Thanks,

  • Ian - thanks for pointing that out. I should have mentioned it :S I've updated the article above a little to try and help. Basically I only add these ads on the single posts, either in the single.php template or in index.php. I place the code in the "wordpress loop".

    Does any of that make sense?

  • That was enough info for me to sort it out. I tried it on one of my less active blogs and it worked like a charm. Thanks for the help.

  • This is the kind of things that makes everyone happy: your dedicated visitors, not seeing your ads, and you, making money from older posts.

  • Interesting, and I won't pretend to fully understand it ;-)

    I understand what the loop is & where to insert code, but it reads like you do this on a post by post basis? Or have you just inserted this into single.php and once a post reaches a set age, the adsense drops in?

    Sorry if I'm being thick, I'm one of those dangerous people who knows a little about PHP, but only enough to break things!

  • Chris - if you have a single.php template then stick it all in the loop in there. It will take care of everything else automatically - you certainly don't need to do it per post.

    Copes - that's the plan :)

  • Nice. I had added your blog to my rss reader, more less just for that ;) . I just came across this via ProBlogger: http://www.dailyblogtips.com/...dsense-wordpress-plugin/

    Which seems to do similar to yours and easier for the less techy people.

    Cheers, Yourhighness

  • this sounds like a good idea to me! Todd

  • I'm having a Blogger blog. Is there a possibility of implementing such a system in a blogpost blog?

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About me

About BenMy name is Ben Gillbanks. I'm a lover of Video Games, WordPress, Web Development and everything in between.

I have been working on the internet since 1998, and working with computers even longer. I am a hardcore Nintendo fanboy and have owned most of their consoles at one stage or another.

Read more about me on my about page.


Follow Me


Random Link-outs

The Binary Network links to all my websites
bengillbanks.co.uk - Ben Gillbanks

Ben Gillbanks

All my websites under 1 roof, the easiest way to find out what I do

Pro Theme Design - premium WordPress themes

Pro Theme Design

Premium WordPress themes by web design pros (erm... that includes me)

Binary Joy - gaming news and reviews

Binary Joy

Gaming news and reviews

Binary Sun - play free online games

Binary Sun

Play and download free and paid games (many made by me)

Gaming Angel - download and play games online

Gaming Angel

Stacks of shareware games, free to try and cheap to buy