有时候会碰到特殊的需求,比如调用文档的发布时间,想要显示几天前、几分钟前、几秒前的效果,这时候需要对程序二次改进来完成。
实现效果:

1:打开 /include/extend.func.php 在最下面加入以下代码
05 | * @param string $ time 时间戳 |
08 | if (!function_exists( 'tranTime' )) |
10 | function tranTime($ time ) |
12 | $rtime = date ( "m-d H:i" ,$ time ); |
13 | $htime = date ( "H:i" ,$ time ); |
14 | $etime = time () - $ time ; |
15 | if ($etime < 1) return '刚刚' ; |
17 | 12 * 30 * 24 * 60 * 60 => ' 年 前' , |
18 | 30 * 24 * 60 * 60 => ' 个 月 前' , |
19 | 7 * 24 * 60 * 60 => ' 周 前' , |
20 | 24 * 60 * 60 => ' 天 前' , |
25 | foreach($interval as $secs => $str) |
|
2:调用标签写法
首页/列表页
[field:pubdate function="tranTime(@me)"/]
内容页
{dede:field.pubdate function="tranTime(@me)"/}
如果你的时间格式是 2018-10-10 这种正常时间,那要这样写调用标签
[field:pubdate function="tranTime(GetMkTime(@me))"/]
{dede:field.pubdate function="tranTime(GetMkTime(@me))"/}
上一篇:织梦程序自定义热门搜索关键词
下一篇:织梦会员模板其他页面引入默认模板的头部尾部