您的位置:首页 > 其它

【帝国CMS】时间格式改成几分钟,几小时,几天前等插件

2017-10-21 15:57 567 查看
在网上试了好几个,终于通过各种组合,成功了一个,发出来给大家看看,同时六个备份,以便以后自己使用。在此还是得感觉懂代码的贡献者。不多说,放码。

把以下的内容复制到 /e/class/userfun.php 文件里,放在<?php和?>之间就可以了。

function user_time($tm, $num) {
if ($num == 1) {
$tm = strtotime($tm);
}
$cur_tm = time();
$dif = $cur_tm - $tm;
$pds = array('秒', '分钟', '小时', '天', '周', '个月', '年');
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560);
for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); $v--);
if ($v < 0) $v = 0;
$_tm = $cur_tm - ($dif % $lngh[$v]);
$no = floor($no);
$x = sprintf("%d%s", $no, $pds[$v]);
return $x."前";
}

然后在帝国cms模版里放入相应的时间标签。

1、在标签模板、列表模板中的调用:

'.user_time($r[newstime],0).'

2、在内容页中调用:
<?=user_time($navinfor[newstime],0)?>
3、在评论JS调用模板调用方法:

在评论JS调用模板把
[!----pltime--]换成
<?=user_time($r[saytime],1)?>

然后打开e\pl\more\index.php ,找到:
require("../../class/connect.php");
下一行加入以下代码:
require("../../class/userfun.php");
然后保存。

具体信息,请查看:http://www.16css.com/ecms/934.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐