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;
  • About the question What exact part should display your default image and how did you add a default image? Formatting & the WYSIWG editor: Jamie, please take care about formatting. You want an answer, so please take your time to format your question as well as possible. Thanks. – kaiser Sep 22 '12 at 21:38
  • 1
    I will do my best to improve my formatting and details in my questions from now on. – Jamie Sep 23 '12 at 2:50

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 );

  • Not, that the question is really clear, but how does this answer "(...)It does display the default avatar but is should display my image which it is not." ? – kaiser Sep 23 '12 at 2:06
  • it's interesting how sometimes reading the codex and send you off in the wrong direction. This worked. Thank you – Jamie Sep 23 '12 at 2:49
  • kaiser: Sometimes you have to read between the lines. ;) – Otto Sep 23 '12 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.