1. 程式人生 > >【帝國CMS】時間格式改成幾分鐘,幾小時,幾天前等外掛

【帝國CMS】時間格式改成幾分鐘,幾小時,幾天前等外掛

在網上試了好幾個,終於通過各種組合,成功了一個,發出來給大家看看,同時六個備份,以便以後自己使用。在此還是得感覺懂程式碼的貢獻者。不多說,放碼。

把以下的內容複製到 /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