首页 > 新闻资讯 > 如何只在WordPress旧日志中显示广告

如何只在WordPress旧日志中显示广告

4条评论
标签:

你的常规读者不会点广告的,不对他们显示广告也是一种尊重。如何只在发布超过15天的日志里显示广告?

先把以下代码贴进functions.php文件:

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;
}

把显示广告的地方改成这样:

<?php if(is_old_post()){ ?>
广告代码贴到这
<?php } ?>

大功告成!

* 版权声明:作者WordPress啦! 转载请注明出处。

#1
厉害厉害!
#2
我目前没使用广告。O(∩_∩)O哈哈~
#3
我也还没有放广告,博客中的广告还是少点好
#4
我新接触这套BLOG程序呢,看下怎么弄

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.