今天有个群友有个特殊的需要,他希望自己新发布的文章内容中不限制广告,但是希望在指定的天数后面再显示。比如一周、两周后才显示广告,那这样如何设置呢?这里老蒋找呀找,找到一个不错的办法,可以设置在特定的内容延迟显示。
第一步、先定义功能

//定义广告显示时间周期功能 itbulu.com
function delay_ads_post($post_id=null){
$days = 7;
global $wp_query;
if(is_single() || is_page()) {
if(!$post_id) {
$post_id = $wp_query->post->ID;
}
$current_date = time();
$offset = $days 6060*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;
}

我们需要先定义个功能在当前主题功能页面,设置7天后显示的定义。
第二、调用内容
< ?php if(delay_ads_post()){ ?>
延迟显示的内容
< ?php } ?>

在我们需要显示的内容位置调用。这样就会在7天后内容中显示需要展示的广告。


扫描二维码,在手机上阅读!