给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');
文章内插入:
功能调用也很简单,如下在文章中你认为合适的地方加入以下代码即可。
总结
通过以上方法,如果你学会了,快点部署到自己的WordPress网站上吧,最后别忘记收藏,分享本站哦。
常见问题FAQ
- 美化包支持最新版本吗?
- 最新美化支持永久更新!