3

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;
}
2
  • 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
    Commented Sep 22, 2012 at 21:38
  • 1
    I will do my best to improve my formatting and details in my questions from now on.
    – Jamie
    Commented Sep 23, 2012 at 2:50

1 Answer 1

3

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

3
  • 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
    Commented Sep 23, 2012 at 2:06
  • it's interesting how sometimes reading the codex and send you off in the wrong direction. This worked. Thank you
    – Jamie
    Commented Sep 23, 2012 at 2:49
  • kaiser: Sometimes you have to read between the lines. ;)
    – Otto
    Commented Sep 23, 2012 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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