开发者

Wordpress' post_time won't work with Custom PHP time difference calculator

I'm using this script (http://snipplr.com/view/4912/relative-time/) to create relative times using PHP and tim开发者_如何学编程estamps stored in my database. I'm using the standard format for storing datetime (eg 2010-05-07 20:26:17) and it works fine with any timestamps I create.

But for some reason when I try to use a timestamp stored in wordpress's wp_posts table, the function fails and returns "January 1, 1970". I can't see any difference in the format of wordpress' timestamps and my own. And I can use wordpress' data fine using the date() function to present a formatted date, just not a relative time using my own function.


If you can use the dates fine with date() then you probably have them in UNIX timestamp format already. Try removing the strtotime() calls in getRelativeTime() (on line 7 and 22).


You don't need that script - WordPress has a human time difference function you can use

To print an entry's time ("2 days ago"):

<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>

For comments:

 <?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜