<?php human_time_diff( $from, $to ) ;?>
//将你的评论时间显示的函数改成如下就可以了
<?php echo human_time_diff( get_comment_time('U') , current_time('timestamp')) ;?>
<?php
//计算是否超过一天 注:86400是一天的总共的秒数 60秒X60分X24小时=86400秒
//如果觉得一天不够的话,请自行计算填上。
if (current_time('timestamp') - get_comment_time('U') < 86400 )
//一天之内显示的东西
{$cmt_time = human_time_diff( get_comment_time('U') , current_time('timestamp') ) . '-ago';}
//超过一天这么显示
else{$cmt_time = get_comment_date( 'Y/n/j' ).' - '.get_comment_time('','',false);};
;?>
//将你的评论时间显示的函数改成如下就可以了
<?php echo $cmt_time ;?>
//原函数的 day hour min 都是小写的,
//我把这三个词的首写字母改成大写的,即Day Hour Min 就可以避开汉化了,你懂?
if ( ! function_exists( 'xz_time_diff' ) ) :
function xz_time_diff( $from, $to = '' ) {
if ( empty($to) )
$to = time();
$diff = (int) abs($to - $from);
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);
}
return $since;
}endif;
<?php
//只是把计算日期差异的函数名变了而已,其他同上。
if (current_time('timestamp') - get_comment_time('U') < 86400 )
{$cmt_time = xz_time_diff( get_comment_time('U') , current_time('timestamp') ) . '-ago';}
else{$cmt_time = get_comment_date( 'Y/n/j' ).' - '.get_comment_time('','',false);};
;?>
//将你的评论时间显示的函数改成如下就可以了
<?php echo $cmt_time ;?>
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;
//最简单的调用
echo xz_time('cmt');
//一天内的输出结果: 3 Hours-ago
//一天后的输出结果: 2015/12/26 - 20:01
//调用时长为2天内的相对时间,之前时间显示默认时间
echo xz_time('cmt',172800);
//2天内的输出结果: 3 Hours-ago
//2天后的输出结果: 2015/12/26 - 20:01
//调用时长为2天内的相对时间,相对时间之后显示 '之前的评论'
echo xz_time('cmt',172800,'之前的评论');
//2天内的输出结果: 3 Hours 之前的评论
//2天后的输出结果: 2015/12/26 - 20:01
//调用时长为2天内的相对时间,之前时间显示为 年-月-日
echo xz_time('cmt',172800,'之前的评论',get_comment_time('Y-n-j'));
//2天内的输出结果: 3 Hours 之前的评论
//2天后的输出结果: 2015/12/26
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有