帝国cms实现发布时间为几小时前几天前等格式的方法

帝国cms实现发布时间为几小时前几天前等格式的方法

来源:帝国CMS模板网 作者:帝国CMS教程 时间:2015-12-27
浏览:2.8千+ 收藏 点赞(1)
简介: 帝国cms7.2怎样实现时间为:几小时前、几天前等格式将以下代码放到:userfun.php ph 之间function user_time($tm,$num) {if($num==1){   $tm =  strtotime($tm);}  

帝国cms7.2怎样实现时间为:几小时前、几天前等格式

将以下代码放到:userfun.php

 <?ph ?>

之间

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."前";
}

列表模板调用:

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

(注:需要列表放代码) 

内容模板调用:

<?=user_time($navinfor[newstime],0)?>
帝国CMS模板网 帝国CMS模板网(www.daixiao360.cn)长期承接帝国CMS模板定制,帝国CMS仿站,帝国CMS采集规则,帝国CMS插件,帝国CMS二次开发。