• 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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Connor Crosby

    (@ccmovies)

    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.

    I am looking to create something myself, not a plugin

    Sure, but download the plugin and then pick up the code from there….

    Thread Starter Connor Crosby

    (@ccmovies)

    The only problem is that I am kinda new to PHP so I am not exactly sure how I can accomplish that. Thank you.

    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Twitter-Like Time Ago’ is closed to new replies.