In every post/article I want to show the author name and date of the last comment added to that post/article. I use the code below to return this information.
If there are one or more comments for a post/article it says:
Last comment: Author on 4 Jun 2008 @ 10:11
When there are no comments I would like to see:
Last comment: –
How do I do this? I tried to set
comments_number = $zerowith an is statement. Also tried to change
comments_number('Last comment: - ', '<em>all of the code below</em> ', '<em>all of the code below</em> ' );
<?php // this shows the last comment author and date $last_comment = mysql_fetch_assoc(mysql_query(" SELECT comment_ID, comment_author, comment_content, date_format( comment_date, '%e %b %Y @ %k:%i' ) AS formatted_date FROM wp_comments WHERE comment_post_ID = ".$id." ORDER BY comment_date DESC LIMIT 1")); ?> Last comment: <a href="<?php echo the_permalink().("#comment-"),$last_comment['comment_ID']; ?>" title="View comment"><?php echo $last_comment['comment_author']; ?></a> on <?php echo $last_comment['formatted_date']; ?>
- The topic ‘How to check if an article has comments or not?’ is closed to new replies.