trying to get wordpress comments to show comment content inside

On my home page. I want the a list of comments to show with the users comment, attached with their avatar, name and what category the comment is attached to.

At this moment i have these results from the below image

Read More

enter image description here

I cant seem to get the actual content of the message to appear in the loop along with the category that the post is attached to.

<?php
$total_comments = $wpdb->get_results("SELECT comment_date_gmt, comment_author, comment_ID, comment_post_ID, comment_author_email FROM $wpdb->comments WHERE comment_approved = '1' and comment_type != 'trackback' ORDER BY comment_date_gmt DESC LIMIT 10");
$comment_total = count($total_comments);
echo '<ul>';
for ($comments = 0; $comments < $comment_total; $comments++) {
echo "<div style='clear:both;width:355px;padding-top:3px;'><div style='float:left;width:35px;'>";
echo get_avatar($total_comments[$comments]->comment_author_email,$size='32',$default='<path_to_url>' );
echo "</div> <div style='width:320px;'>";
echo '<li>';
echo $total_comments[$comments]->comment_author . ' says ';
echo '<a href="'. get_permalink($total_comments[$comments]->comment_post_ID) . '#comment-' . $total_comments[$comments]->comment_ID . '">';
echo get_the_title($total_comments[$comments]->comment_post_ID);
echo '</a></li></div></div>';
}
echo '</ul>'
?>

How would i go about adding the comment_content and its category?

EDIT. Here is what i have found that shows something close to my prefeered answer

<?php
$comments = get_comments('status=approve&number=5');
  foreach($comments as $comment) :?>

  <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 

    Who: <?php echo($comment->comment_author);?><br />
    About: <a href="<?php echo get_permalink($my_id) ?>#comment-<?php echo $comment->comment_post_ID?>" title="on <?php echo $title ?>"><?php echo $title ?></a><br />
    What they said: <?php echo($comment->comment_content);?><br />
    When they said it: <?php echo($comment->comment_date);?><br />

  <?php endforeach;?> 

Related posts

Leave a Reply

1 comment

  1. Try get_comments() instead, it’ll give you most of the information you need and to get the category of a post from comment you can use get_the_category function inside the loop, for example

    $comments = $comments = get_comments( array('status') => 'approve' );
    foreach($comments as $comment) {
        echo $comment->comment_content;
        $categories = get_the_category( $comment->comment_post_ID );
        foreach($categories as $category) {
            echo $category->cat_name;
        }
    }