WP模板阁数千套各行业Wordpress模板随你选,总有一款适合你的网站![收藏本站] 注册 登录

WordPress网站如何添加倒计时功能

        发布:WP模板阁 类型:wordpress教程 浏览:633 次

有时我们网站上想放一个活动的倒计时牌,怎么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=12″ day=20″ year=2019]本次活动已过期,请下次再来哦![/ccdt]

通过以上方法,如果你学会了,快点部署到自己的WordPress网站上吧。