织梦实现文章发布时间显示为几分钟前几小时前几天前几个月前的格式
林土晓55 次
Panda PRO主题的首页文章列表调用的发布时间是多少分钟前,多少小时前,多少个月前,多少年前这个格式的,织梦又是如何实现实现文章发布时间为几分钟前几小时前几天前几个月前的格式这种效果的呢?
只需要两步!
step 1.找到 文件 include/extend.func.php ,在最下面添加下面的代码
/**
*文章发布多少时间前
*by www.imatx.com
*/
function tranTime($time) {
$today = Floor(time()/3600 * 24);
$senday = Floor($time()/3600 * 24);
$updays = $today - $senday;
if ($time < 60) {
$min = floor($time / 60);
$str = $min.'分钟前';
}
elseif ($time < 3600 * 24) {
$h = floor($time / 3600);
$str = $h.'小时前 '.$htime;
}
elseif ($time >= 3600 * 24 && $time < 3600 * 24 * 30 * 365) {
$m = floor($time / (3600 * 24));
$str = $m.'个月前 ';
}
elseif ($time >= 3600 * 24 * 30 * 365) {
$y = floor($time / (3600 * 24 * 365));
$str = $y.'年前 ';
}
else {
$str = $rtime;
}
return $str;
}
step 2.如何调用呢?
列表页:[field:pubdate function="tranTime(me)"/]
内容页:{dede:field.pubdate function="tranTime(me)"/}
搞掂,最终效果可以浏览我的首页查看。

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。
转载请注明来源:织梦实现文章发布时间显示为几分钟前几小时前几天前几个月前的格式 - 林晓博客
评论 | 0 条评论