在博客举办活动时此代码会比较常用(比如T楼)。设置后,文章内容将会显示『本篇文章内容在X天后可见』,既给访客良好的浏览体验,也为网站添加了「饥饿营销」的作用(某米你听好了)。
WordPress实现活动
主题目录 functions.php 内插入以下代码:
function content_countdown($atts, $content = null){
extract(shortcode_atts(array(
'month' => '',
'day' => '',
'year' => ''
), $atts));
$remain = ceil((mktime( 0,0,0,(int)$month,(int)$day,(int)$year) - time())/86400);
if( $remain > 1 ){
return $daysremain = "<div class=\"alert alert-success\"><center>本篇文章内容<b>($remain)</b>天后可见,请耐心等待哦~</center></div>";
}else if($remain == 1 ){
return $daysremain = "<div class=\"alert alert-info\">本篇文章内容<b>($remain)</b>天后可见,请耐心等待哦~</div>";
}else{
return $content;
}
}
add_shortcode('ccdt', 'content_countdown');
文章内插入:
[ccdt month=”10″ day=”17″ year=”2011″]本次活动已过期,请下次再来!!![/ccdt]

