0

我正在用表达式引擎构建博客。我想显示条目发布了多长时间。我怎样才能获得多小时/天前发布的频道条目?

谢谢

4

1 回答 1

0

我已经解决了这个问题,

在我的模板中,我允许 PHP

然后我添加我从http://css-tricks.com/snippets/php/time-ago-function/找到的这段代码

但不要使用函数,我不知道,但它给了我错误。像这样直接进入主要内容:

<?php
$time = strtotime("{entry_date format="%d %F %Y"}");
   $periods = array("Second", "Minute", "Hour", "Day", "Week", "Month", "Year", "Decade");
   $lengths = array("60","60","24","7","4.35","12","10");

   $now = time();

       $difference     = $now - $time;
       $tense         = "ago";

   for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
       $difference /= $lengths[$j];
   }

   $difference = round($difference);

   if($difference != 1) {
       $periods[$j].= "s";
   }

   echo "$difference $periods[$j] Ago";

?>

可以帮助另一个和我有同样问题的人

于 2013-05-28T15:06:26.737 回答