How to Display an Author List with Avatars in WordPress: Redux

Posted on August 17, 2009  |  Category: Tutorials

WordPress has a built in function to display a list of all of your site’s authors. But there is no option to display their avatars, so all you really get is a text list that links to the author’s page, if you have an author.php file in your theme, that is. I needed to also display the authors’ avatars for a client so I came up with a little piece of code that seems to do the trick.

NOTE: The old piece of code only worked if you were using pretty permalinks, and it was a little clunky.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function contributors() {
global $wpdb;
 
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
 
foreach($authors as $author) {
echo "<li>";
echo "<a href=\"".get_bloginfo('url')."/?author=";
echo $author->ID;
echo "\">";
echo get_avatar($author->ID);
echo "</a>";
echo '<div>';
echo "<a href=\"".get_bloginfo('url')."/?author=";
echo $author->ID;
echo "\">";
the_author_meta('display_name', $author->ID);
echo "</a>";
echo "</div>";
echo "</li>";
}
}

I also had to add some CSS to my style.css file to make it look the way I wanted.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#authorlist li {
	clear: left;
	float: left;
	margin: 0 0 5px 0;
	}	
 
#authorlist img.photo {
	width: 40px;
	height: 40px;
	float: left;
	}
 
#authorlist div.authname {
	margin: 20px 0 0 10px;
	float: left;
	}

NOTE: If you are using the User Photo plugin you can replace echo get_avatar($author->ID); with echo userphoto($author->ID);


Tags: , , , , , , , , , , , , , ,

Short URL: http://bavotasan.com/?p=433

28 Responses to “How to Display an Author List with Avatars in WordPress: Redux”

  1. DarioDN

    Sorry. I tried but it doesn’t works… the list is ok but no avatar appears!
    I’m using userphoto

    #1022
    • DarioDN

      the output is only

      User
      USer
      USer

      #1023
    • Did you change the code so that it has userphoto($id); instead of get_avatar($id);? You might also need to make sure that you have avatars turned on under you admin panel in Settings => Discussions.

      #1044
    • Claude

      Hi!

      i seem to have the same problem, i get just a list when i have userphoto($id); in the code. with get_avatar($id); it shows the avatar…any idea what i’m doing wrong? Avatars are turned on…
      cheers!

      #2187
    • Claude

      thanks for sharing your code!
      i’m using it and it’s working with get_avatar($id); but when i insert userphoto($id); i only get a list of the users but no pics. user-photo is installed and working…
      do you have any idea what i can do to solve this?

      #2226
  2. What if you don’t have ‘authors.php’. Can it manually be added to magazines (2.3.3)?

    #1381
  3. Can you link us to a page that demonstrates this code’s output? I recently wrote my own code to do something similar, as seen at the link in this comment’s byline; I’d like to see how they compare.

    #1898
  4. david

    Thank you for posting this but I’m having trouble getting user_photo to display. I swapped out the get_avatar text with userphoto. Userphoto is working on the individual author pages and on the posts themselves but not working when trying to list all authors. I’m not sure what I’m doing wrong.

    #2218
  5. Thank you for this code.
    It worked fine on the normal website, when permalinks are on the images will not load. Do you have a solution for this?

    #2726
  6. Rebecca

    amazing!! thank you! Only question – how do I add the bio / description as well?

    #2732
  7. I tried this on my blog, but I get the same avatar for all users. Any idea what could be causing that?

    #3195
  8. Sacit

    Thank you for this code.

    In addition to this code, I click on the author would like to list in the title. list, the title belongs to the author, the date of writing articles for the category. Would this help with

    #3287
  9. Is there anyway to incorporate a command to display the author’s description as well?

    #3440
  10. Jonas

    Is there anyway to get the latest post under the name aswell?
    Would be much apriciated…Thx in advance

    #3777
  11. The function works perfectly; thank you very much! Is there a way to make it skip listing admin?

    #3877
    • Just replace line #4 of the first part with:

      $authors = $wpdb->get&#95;results("SELECT ID, user&#95;nicename from $wpdb->users WHERE display&#95;name <> 'admin' ORDER BY display&#95;name");
      
      #3880
  12. I will tested on my blog, thanks for sharing this code

    #3897
  13. Hi this is what i want. but i want to create a slider and display all the authors on a wordpress blog with image and short description. what should i have to display small description and author image.

    #5452
    • Use the following to display the description:

      the_author_meta('description', $author->ID);

      Add it to the above wherever you would like it to appear. Surround it with a div to style it.

      #5554
  14. Works great. Is there any way to sort author list by most number of post?

    #5813
  15. hello, thanks for the tip! But im having problems uploading the image in User Photo Plugin. When i upload it doesn´t show any image. Do you know what it could be?

    #6684
  16. how to change w&h grafatar images?

    #6875

Leave a Reply

To enter code in the comment box, please place it between <pre lang="php"> </pre> tags. You don't have to convert any characters to their hex/HTML code. Just add your code the way you would to any code editor.