Browsed by
Category: 未分类

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');
Shell中判断前一个命令是否执行成功

Shell中判断前一个命令是否执行成功

Linux Shell中常用的判断语法:

  • -eq  等于
  • -ne  不等于
  • -gt  大于
  • -lt  小于
  • ge  大于等于
  • le  小于等于

代码如下:

if [ $? -ne 0 ]; then
    echo "fail"
else
    echo "success"
fi

或者

if [ $? -eq 0 ]; then
    echo "success"
else
    echo "fail"
fi