• 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 = $zero with 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']; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lucas_man

    (@lucas_man)

    When there are no comments WP returns
    Last comment: on

    How can I check if there are comments or not so I can change ON into – when there are not comments!

    So something like:

    <?php      if ($comments)
            echo("op");
    else
            echo("no");          ?>

    ?????

    Thread Starter lucas_man

    (@lucas_man)

    Already got it

    Changed the part that says ‘on’ into: <?php if ($comments); comments_number(‘ – ‘, ‘ on ‘, ‘ on ‘ ); ?>

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.