treehouse : what would you like to learn today?
Web Design Web Development iOS Development

WordPress comments "time ago" feature

  • Hey guys.

    I'm using this code to show relative comment time, but only if the comment is less than a week old. Otherwise it should show the full date, including the year if it was posted in a year other than the current one.

    <?php if ( get_comment_time('U') > date('U') - 7*60*60*24 ) { echo human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago'; } elseif ( get_comment_date('Y') == date('Y') ) { comment_date('F j'); } else { comment_date('F j, Y'); } ?>

    It works, but I'm having a problem with the "Live Comment Preview" plugin. In it, the "time ago" is displayed as a seemingly random number of days ago...over a million every time.

    How can I improve the code to make it just echo the standard date in the Comment Preview box?

    Thanks.