show author image in posts

I need to display author image along with posts. I used the following code to display posts with author image.

$the_query = new WP_Query("post_type=post&paged=".get_query_var('paged'));
while ( $the_query->have_posts() ) : $the_query->the_post();

<?php the_excerpt(); ?>
<p><?php the_author_image(); ?></p>

<?php endwhile; ?>

But the author image didn’t display. I couldn’t track the error. How can i do this?

Related posts

Leave a Reply

4 comments

  1. I know this is old, but I just came across it shortly before I came across the solution.

    To display the author image inside the loop, just use this code:

    <?php echo get_avatar( get_the_author_meta( 'ID' ) , 32 ); ?>
    

    Where ’32’ is the size of the image. If it’s outside the loop, then just specify the author’s user ID.

  2. If you are not using it inside a normal loop, get the author ID a different way and use the function like this:

    the_author_image($authorid);
    

    Basically you need to supply the author ID to the function if it is not in a proper loop. If you are having trouble getting the ID from your query let me know.

  3. Note the answers here are for the built-in Gravatar photo. If you want to choose/set photos for your authors you’ll need a plugin or write your own as miahelf mentions.

  4. Upload a specific image for author requires 2 things:

    • extend the get_the_author_meta() function
    • link the implementation of the extension to media file management system in WP

    Please Note that get_the_author_image() is deprecated and will not work for WP > 3.0