Show your ads on only old posts!

We use Google Adsense or any other ad servers for make money :) You can use this ads on your old posts. I don’t know any pluginfor that function but we can make a function for use ads… Let’s begin…

Here is the code;

To use this code open your functions.php and paste this code into end of file.

function is_old_post($post_id=null){
   $days = 15;
   global $wp_query;
   if(is_single() || is_page()) {
      if(!$post_id) {
         $post_id = $wp_query->post->ID;
      }
      $current_date = time();
      $offset = $days *60*60*24;
      $post_id = get_post($post_id);
      $post_date = mysql2date('U',$post_id->post_date);
      $cunning_math = $post_date + $offset;
      $test = $current_date - $cunning_math;
      if($test > 0){
         $return = true;
      }else{
         $return = false;
      }
   }else{
      $return = false;
   }
   return $return;
}

After that use this code for show your ads…

<?php if(is_old_post()){ ?>
INSERT AD CODE HERE
<?php } ?>

This function show ads on your 15 days old posts. To change this simply change $days value


Related posts:

If you enjoyed this post, make sure you subscribe to my RSS Feed
  1. Feb 17th, 2010 at 19:05 | #1

    Good tutorial… thanks ..

  2. Feb 19th, 2010 at 11:20 | #2

    You’re Welcome!

Comments are closed.
Highslide for Wordpress Plugin