if ( ! function_exists( 'xz_time' ) ) :
/**
* 显示文章、评论相对时间的封装函数.
*作者:XiangZi http://PangBu.com/
* @param $type 类型字符串 'cmt'或'art',用于定义显示的是评论时间还是文章时间。
* @param $ago_time 数字类型 用于定义显示相对时间的时间限制 默认为86400秒即一天。
* @param $after 字符串型 显示在相对时间之后的文字,默认为 ' - ago'
* @param $late 字符串型 超过时间限制后显示的项目,默认为 get_the_time('Y/n/j - H:i')或get_comment_time('Y/n/j - H:i')
* @return 返回字符串(相对时间或绝对时间)
*/
function xz_time ( $type = 'art', $ago_time = 86400 ,$after = ' - ago' , $late = '' ) {
if ( $type === 'cmt' ){
$diff = (int) abs( get_comment_time('U') - current_time('timestamp'));
if ( (!$late) || $late ==''){ $late = get_comment_time('Y/n/j - H:i');};
}
if ( $type === 'art' ){
$diff = (int) abs( get_the_time('U') - current_time('timestamp'));
if ( (!$late) || $late ==''){$late = get_the_time('Y/n/j - H:i');};
}
if ( $diff <= 3600 ) {
$mins = round($diff / 60);
if ($mins <= 1) {
$mins = 1;
}
/* translators: min=minute */
$since = sprintf(_n('%s Min', '%s Mins', $mins), $mins);
} else if (($diff <= 86400) && ($diff > 3600)) {
$hours = round($diff / 3600);
if ($hours <= 1) {
$hours = 1;
}
$since = sprintf(_n('%s Hour', '%s Hours', $hours), $hours);
} elseif ($diff >= 86400) {
$days = round($diff / 86400);
if ($days <= 1) {
$days = 1;
}
$since = sprintf(_n('%s Day', '%s Days', $days), $days);
};
$since .= $after ;
return $diff < $ago_time ? $since : $late ;
}endif;