Hello, I am making a wordpress theme and I would like to know how to display the time like Twitter does. For example: 1 minute ago, 5 minutes ago, 1 hour ago, and then if it has been more than 1 day ago it displays the actual date of the post (October 1st, 2010 or whatever I put for the time).
I know I can use PHP or put it in the functions.php however I am just starting out. How can I accomplish this? I appreciate the help!
JohnC28
Member
Posted 2 years ago #
Thanks but I am looking to create something myself, not a plugin. That plugin only displays how many --- ago and doesn't show the actual date after a certain time.
JohnC28
Member
Posted 2 years ago #
I am looking to create something myself, not a plugin
Sure, but download the plugin and then pick up the code from there....
The only problem is that I am kinda new to PHP so I am not exactly sure how I can accomplish that. Thank you.
JohnC28
Member
Posted 2 years ago #
You need the PHP DateInterval class.
Use it to get the difference between now and the post date (get_the_date() from WP3 onwards) and then a set of if statements to determine which format you want:
Pseudo:
if < 60 seconds
n seconds ago
if < 60 minutes
n minutes ago
if < 24 hours
m hours ago
else
date
Good luck.
John