国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > 織夢DEDE > 正文

織夢顯示發布時間為多少時間前的實現方法

2024-07-12 09:02:06
字體:
來源:轉載
供稿:網友

織夢的文章發布時間調用格式一般分為一下這些:

[field:pubdate function="MyDate('Y-m-d',@me)"/]2013-12-17[field:pubdate function=MyDate('m-d',@me)/]12-17[field:pubdate function=MyDate('y-m-d',@me)/]13-12-17[field:pubdate function='strftime("%y-%m-%d %H:%M:%S",@me)'/]13-12-17 10:35:21[field:pubdate function='strftime("%m-%d %H:%M:%S",@me)'/]12-17 10:35:21[field:pubdate function='strftime("%y年%m月%d日",@me)'/]13年12月17日[field:pubdate function='strftime("%Y年%m月%d日 %H點%M分%S秒",@me)'/]13年12月17日 12點12分30秒

 

有的時候,我們想做到不直接顯示具體時間,而是以幾天前、幾月前這樣的時間間隔方式來顯示, 更利于讓訪客直觀地看到文章的發布時段,以上的調用方法則不適用了。

教大家如何實現顯示發布時間為多少時間前,主要有兩種方法。

 

一、模板直接寫PHP語句

[field:pubdate runphp='yes']$today = Floor(time()/(3600 * 24));$senday= Floor(@me/(3600 * 24));$updays = $today-$senday;if($updays >= 30 && $updays < 60) @me="1個月前";elseif($updays >= 60 && $updays < 90) @me="2個月前";elseif($updays >= 90 && $updays < 120) @me="3個月前";elseif($updays >= 120 && $updays < 150) @me="4個月前";elseif($updays >= 150 && $updays < 180) @me="5個月前";elseif($updays >= 180 && $updays < 210) @me="6個月前";elseif($updays >= 210 && $updays < 240) @me="7個月前";elseif($updays >= 240 && $updays < 270) @me="8個月前";elseif($updays >= 270 && $updays < 300) @me="9個月前";elseif($updays > 300 && $updays < 330) @me="10個月前";elseif($updays > 330 && $updays < 360) @me="11個月前";elseif($updays >= 360) @me="一年前";elseif($updays==0) @me = "今日";else @me = $updays."天前";[/field:pubdate]

 

二、自定義函數

在include/extend.func.php文件中加入以下代碼:


 

  //文章發布多少時間前        function tranTime($time) {        $today = Floor(time()/(3600 * 24));        $senday= Floor($time/(3600 * 24));        $updays = $today-$senday;        if($updays==0)        $str = '今天';        elseif ($updays >=1 && $updays < 31) {                $str = $updays.'天前 ';        }        elseif ($updays >= 31&& $updays < 365) {                $m = floor($updays / 31);                $str = $m.'月前 ';        }            elseif ($updays >= 31&& $updays < 365) {                $y = floor($updays / (31* 365));                $str = $y.'年前 ';        }        else {                $str = $rtime;        }        return $str;                                                      }

如果要顯示幾分鐘和幾小時,則自行加入判斷函數

        

elseif ($updays >0 && $updays < 1 ) {        $h = floor($updays * 24);        $str = $h.'小時前 ';        }

 

調用方法

列表頁:[field:pubdate function="tranTime(@me)" /]

內容頁:{dede:field.pubdate function="tranTime(@me)"/}

 

以上兩種方法都可以實現調用,第一種方法是直接把php語法寫入模版中,會顯得文件比較冗余,建議使用第二種自定函數的方式,簡單明了。

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 社会| 龙口市| 柳河县| 故城县| 烟台市| 樟树市| 额敏县| 蒙城县| 遵义县| 长治县| 民县| 洞口县| 内黄县| 宝应县| 临夏市| 麻阳| 元谋县| 云梦县| 迁西县| 纳雍县| 金山区| 定远县| 苍溪县| 鄂托克前旗| 马关县| 敦化市| 苍溪县| 通城县| 靖安县| 和林格尔县| 商城县| 巴楚县| 平南县| 石门县| 安图县| 大埔县| 邯郸市| 肇州县| 怀宁县| 化州市| 岳阳市|