Support » Fixing WordPress » Last comment in archive or category

  • Resolved ABTOP


    Typically the archive and category pages show a list of articles with the standard information, such as article’s author, date and time, number of comments.

    I would also like to show the link to the last comment for that article , its author and the date/time.

    How can this be done?

Viewing 1 replies (of 1 total)
  • One would think it was a simple question, but operantly not.

    OK then, I am trying to come up with a mySQL query to accomplish the same thing, although my knowledge of mySQL and PHP is just about non-existent. Here’s what I came up with:

        $result = mysql_query("SELECT comment_post_ID,comment_author,comment_date
        FROM wp_comments
        WHERE comment_approved = 1
        ORDER BY comment_ID DESC
        LIMIT 1"
        while ($row = mysql_fetch_assoc($result))
           echo $row["comment_author"];
           echo "<br>";
           echo $row["comment_date"];
           echo " <b>>></b> ";
           echo $row["comment_post_ID"];
           echo "<br>";
        echo "End of query!";

    The problem with this script is that all the comments for all the posts are pulled out, not just for the related post. I need to enter some sort of criteria to tie comment_post_ID column from table wp_comments and ID column from wp_posts, but so far I tried adding after WHERE
    AND wp_comments.comment_post_ID = wp_posts.ID
    but then I get syntax errors.

    Would anybody know how to do a look-up by the related field only?

Viewing 1 replies (of 1 total)
  • The topic ‘Last comment in archive or category’ is closed to new replies.