How to check if an article has comments or not?
-
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:11When there are no comments I would like to see:
Last comment: –How do I do this? I tried to set
comments_number = $zero
with an is statement. Also tried to changecomments_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']; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to check if an article has comments or not?’ is closed to new replies.