Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
I don't think the_author_image() is a Wordpress defined function: there is no place to set an image in the edit user profile area of the dashboard. Looks like you need this plugin: wordpress.org/extend/plugins/sem-author-image Otherwise, you would need to upload images of the authors, add a custom field to the user meta table that stores the "attachment" post for that author, then get the meta field data and output it as an <img> tag where you have the_author_image() in the above code. –  miahelf Apr 17 '12 at 7:38
    
you're right. I am using author image plugin for upload author image. If i use the code "while ( have_posts() ) : the_post();" the author image displayed correctly. But i have to use the code "while ( $the_query->have_posts() ) : $the_query->the_post();". Could i get this correctly using the second code? –  designersvsoft Apr 17 '12 at 7:45
add comment

4 Answers 4

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.

share|improve this answer
1  
+1 Thanks for the late answer! It's always beneficial to the community when questions are fleshed out even after they've become stagnant. –  Brian Fegter Sep 21 '12 at 1:50
add comment

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.

share|improve this answer
    
I got the author id correctly but the image didn't display. –  designersvsoft Apr 17 '12 at 8:00
    
Can you try hard coding one of the author id's like this and let me know what happens: the_author_image(5); –  miahelf Apr 18 '12 at 0:09
1  
I just used the query post instead of new wp query and the code "the_author_image($authorid);" works fine for me. Anyway thank you so much for your continuous effort –  designersvsoft Apr 19 '12 at 4:24
    
If you found the solution to your problem, go ahead and post the solution as an answer and accept it, or if you think my post clarified what you need you can accept it instead. –  miahelf Apr 19 '12 at 7:14
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
This is a quite vague answer... –  kaiser Dec 2 '13 at 0:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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