根据刚刚,1分钟前,1小时前,几天前显示文章发布日期
一分钟之内发布的,显示“刚刚”
一小时之内发布的,显示“XX分钟前”
一个月之内发布的,显示“XX天前”
一个月外的直接显示日期。
1 //发表于几分钟前 2 function kele_time_since($older_date, $newer_date = false) 3 { 4 $chunks = array( 5 array(60 * 60 * 24 * 365 , '年'), 6 array(60 * 60 * 24 * 30 , '月'), 7 //array(60 * 60 * 24 * 7, '周'), 8 array(60 * 60 * 24 , '天'), 9 array(60 * 60 , '小时'), 10 array(60 , '分钟'), 11 ); 12 13 $newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date; 14 $since = $newer_date - abs(strtotime($older_date)); 15 16 //根据自己的需要调整时间段,下面的24则表示小时,根据需要调整吧 17 $chunks_count=count($chunks); 18 if($since < 60 * 60 * 24*30){ 19 for ($i = 0, $j = $chunks_count; $i < $j; $i++){ 20 $seconds = $chunks[$i][0]; 21 $name = $chunks[$i][1]; 22 23 if (($count = floor($since / $seconds)) != 0){ 24 break; 25 } 26 } 27 $out = ($count == 1) ? '1'.$name : "$count{$name}"; 28 if(0==$count){ 29 return "刚刚"; 30 } 31 return $out."前"; 32 }else{ 33 the_time(get_option('date_format')); 34 } 35 }

浙公网安备 33010602011771号