You are here: Home » All Categories » » xx天内更新的文章显示oo前

xx天内更新的文章显示oo前

Jul 23rd, 2010 10:18 | Leave a comment?(98) Go to comments

标题很蛋疼,这个功能也蛋疼,类似的也有几个人写过了,我记得万戈写过,貌似qiqiboy也写过,囧~

我还是要写,这是另外一种方法,当然也差不多,无聊罢了。

不啰嗦直接上代码,效果见我博客首页。

方法是使用WordPress内置函数 human_time_diff($from, $to),关于此函数具体看官方codex

把下面的代码放到文章主循环内,就是 while ...... end while 里面啦,替换原来的文章时间。

<?php
 $days = 7;//7天以内发表的文章的显示 xxx 前
 if( current_time('timestamp') - get_the_time('U')<= 60*60*24*$days){
     echo '- ' . human_time_diff(get_the_time('U'), current_time('timestamp')) . ' 前';
 } else {//7天前的直接显示文章发表时间
     echo $time.'- '; the_time(get_option('date_format'));
 }
 ?>

喜欢的、蛋疼的折腾们就加上玩玩

声明: 除非注明,ZWWoOoOo文章均为原创,转载请以链接形式标明本文地址
本文地址: http://zww.me/archives/25211

Filed under

| Tags:

,

Related Posts

Most Popular

98 Comments.

⊕Leave a comment?
  1. 闪闪的星 闪闪的星 Mozilla CompatibleUnknown

    :!: 就这几行呀……

    31楼
  2. Vison Vison Firefox 3.6.6Windows 7

    还是女人好啊,不会蛋疼哈哈

    32楼
  3. 指舞六弦 指舞六弦 Nokia Series60 2.8Nokia Series60

    Z蛮喜欢折腾呢,哈

    33楼
  4. 漏网小鱼 漏网小鱼 UnknownUnknown

    手机测试!

    34楼
  5. TTkea TTkea Firefox 3.6.6Windows 7

    不错,呵呵

    35楼
  6. hzlzh hzlzh Firefox 3.6.6Windows 7

    这个跟微博的用户体验一样,很好,我要加上

    36楼
  7. 掌柜的马甲 掌柜的马甲 Firefox 3.6.7Windows 7

    这个功能确实很蛋疼啊= =

    37楼
  8. 快乐的村长 快乐的村长 Google Chrome 6.0.458.1Windows 7

    32楼号强大,嘿嘿

    38楼
  9. 猪八戒 猪八戒 Firefox 3.6.8Windows XP

    效果呢?没有演示你这个标题很难看懂。

    39楼
  10. zchiy2k zchiy2k Firefox 3.6.8Windows 7

    果真是个挺蛋疼的功能。。。。

    40楼
  11. trylife trylife Firefox 3.6.7Ubuntu 10.04 x64

    蛋疼的孩子,好短;
    这个下拖页面 显示才加载图片很喜欢~

    41楼
  12. 捷易通 捷易通 Internet Explorer 8.0Windows XP

    这样相当于自动更新了吗? :shock:

    42楼
  13. FORECE FORECE Firefox 3.6.8Windows 7

    这个标题好xxoo啊。

    43楼
  14. 阿邙 阿邙 ChromePlus 1.4.0.0Windows 7

    拿走 加上~ :grin:

    44楼
  15. Bee君 Bee君 Firefox 3.6.8Windows XP

    果然是很蛋疼的一个功能 :shock:

    45楼
  16. 洁 Google Chrome 5.0.375.125Windows XP

    万戈的那个代码很长的是不是可以去掉了

    46楼
  17. 一路狂飙 一路狂飙 Firefox 3.0.4Windows XP

    这样的话,网站在国外会不会有问题呀?

    47楼
  18. zigbee zigbee Google Chrome 8.0.552.215Windows XP

    加上了,见到那人new字样呀。怎么?

    48楼

Leave a Reply


Welcome! o(∩_∩)o
X