Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$15
Convert get_comments->comment_date in relative date
some thing like:
Last reply by user_name - 2 hours ago
Now with this code I'm able to display :
Last reply by user_name - 2011-07-29 11:23:31
$comments = get_comments('post_id=' . $post->ID . '&number=1');
if($comments) {
foreach($comments as $comment) :
echo('Last reply by '. $comment->comment_author .
' - ' . $comment->comment_date);
endforeach;
}How can I achieve it?
Just FYI
For timestamps within the looop for both post and comments I can use this function to do so:
if(!function_exists('how_long_ago')){
function how_long_ago($timestamp){
$difference = time() - $timestamp;
if($difference >= 60*60*24*365){ // if more than a year ago
$int = intval($difference / (60*60*24*365));
$s = ($int > 1) ? 's' : '';
$r = $int . ' year' . $s . ' ago';
} elseif($difference >= 60*60*24*7*5){ // if more than five weeks ago
$int = intval($difference / (60*60*24*30));
$s = ($int > 1) ? 's' : '';
$r = $int . ' month' . $s . ' ago';
} elseif($difference >= 60*60*24*7){ // if more than a week ago
$int = intval($difference / (60*60*24*7));
$s = ($int > 1) ? 's' : '';
$r = $int . ' week' . $s . ' ago';
} elseif($difference >= 60*60*24){ // if more than a day ago
$int = intval($difference / (60*60*24));
$s = ($int > 1) ? 's' : '';
$r = $int . ' day' . $s . ' ago';
} elseif($difference >= 60*60){ // if more than an hour ago
$int = intval($difference / (60*60));
$s = ($int > 1) ? 's' : '';
$r = $int . ' hour' . $s . ' ago';
} elseif($difference >= 60){ // if more than a minute ago
$int = intval($difference / (60));
$s = ($int > 1) ? 's' : '';
$r = $int . ' minute' . $s . ' ago';
} else { // if less than a minute ago
$r = 'moments ago';
}
return $r;
}
}and this 2 snippets for post and comments
//post:
if(!function_exists('how_long_ago')){the_time('F jS, Y'); } else { echo how_long_ago(get_the_time('U')); }
//comments:
if(!function_exists('how_long_ago')){the_time('F jS, Y'); } else { echo how_long_ago(get_comment_time('U')); }
But I 'm unable to use this for the above case...
Anyone can help?
This question has been answered.
gino naya | 07/29/11 at 8:28am
Edit
(2) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
07/29/11
8:33am -

Last edited:
07/29/11
8:38amHai Bui says:Please try this:
$comments = get_comments('post_id=' . $post->ID . '&number=1');
if($comments) {
foreach($comments as $comment) :
echo('Last reply by '. $comment->comment_author .
' - ' . how_long_ago(strtotime($comment->comment_date)));
endforeach;
}- 07/29/11 8:43am
gino naya says:works like a charm!
Thanks,
Paolo
- 07/29/11 8:43am
This question has expired.
gino naya voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
