show author avatar

I have modified the loop.php file to add some comment stuff in. I wanted to show a comment off a link which is working just fine. Now I went to make that comment show more detail by putting the author avatar. So my code looks like this. It does display the default avatar but is should display my image which it is not.

 $comments = get_comments( array(
    'post_id' => $post->ID,
    'number'  => '1' 
 ) );
foreach ( $comments as $comment ) {
    echo get_avatar( get_the_author_meta( 'ID'), 32 );
    echo $comment->comment_author . ' says: ';
    echo '<hr />';
    echo $comment->comment_content;
}

Related posts

Leave a Reply

1 comment

  1. The get_the_author_meta function gets the Post’s author ID, not the comment-author’s information.

    The get_avatar() function is perfectly capable of accepting the comment object whole and working it out from that all by itself. So just call it like so:

    echo get_avatar( $comment, 32 );