WordPress短代码实现倒计时显示功能

WordPress短代码实现倒计时显示功能

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=\"event\">Just <b>($remain)</b> days until content is available</div>";
    } else if($remain == 1 ) {
        return $daysremain = "<div class=\"event\">Just <b>($remain)</b> day until content is available</div>";
    } else {
        return $content;
    }
}
add_shortcode('cdt', 'content_countdown');

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据