How to Display an Author List with Avatars in WordPress: Redux
by c.bavota | Posted in Tutorials | 54 comments
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.
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.
#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);



Sorry. I tried but it doesn’t works… the list is ok but no avatar appears!
I’m using userphoto
the output is only
User
USer
USer
Did you change the code so that it has
userphoto($id);instead ofget_avatar($id);? You might also need to make sure that you have avatars turned on under you admin panel in Settings => Discussions.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!
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?
What if you don’t have ‘authors.php’. Can it manually be added to magazines (2.3.3)?
Yup. There is some info on how to make an author.php page at WordPress.org.
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.
I originally wrote this code for a site called http://www.bcscollegefootballboard.info/. You can see it working in their left sidebar.
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.
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?
amazing!! thank you! Only question – how do I add the bio / description as well?
Check out this plugin http://wordpress.org/extend/plugins/author-avatars/
I tried this on my blog, but I get the same avatar for all users. Any idea what could be causing that?
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
Is there anyway to incorporate a command to display the author’s description as well?
Sure. Add the_author_meta() function.
hey, thanks… I was just wasting hours trying to find this exact thing!
Is there anyway to get the latest post under the name aswell?
Would be much apriciated…Thx in advance
The function works perfectly; thank you very much! Is there a way to make it skip listing admin?
Just replace line #4 of the first part with:
Hi,
Can i exclude multiple users from author list?
By the way thank you for this useful information.
I will tested on my blog, thanks for sharing this code
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.
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.
Works great. Is there any way to sort author list by most number of post?
There is probably a way to do this but not with the above code. The users database doesn’t contain any post info so you would have to grab the user ID and then match it up against the posts database table.
Check out http://codex.wordpress.org/Function_Reference/wpdb_Class for more info.
Gah! I needed THIS post so badly, so I feel remiss not trying to be helpful here – sorry to bogart the thread, though. Below, I check if they’re over 20 posts…
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name"); foreach($authors as $author) { if (count_user_posts( $author->ID ) > 20) { echo ""; echo "<a>ID; echo "\">"; echo get_avatar($author->ID); echo "</a>"; echo ''; echo "<a>ID; echo "\">"; the_author_meta('display_name', $author->ID); echo "</a>"; echo ""; echo ""; } }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?
how to change w&h grafatar images?
Great tute, thanks, it works a treat!.
Now, here’s the good part, why not extend this even further, theres a great tute at:
http://wpengineer.com/extend-user-contactinfo-wordpress-29/
which allows you to extend the user contact info, so, you can add any, and show any fields you want now.
here’s my example:
Note how I didn’t want to show my root admin user (ID 1), And I call it like:
//http://bavotasan.com/tutorials/how-to-display-an-author-list-with-avatars-in-wordpress/ function contributors() { global $wpdb; $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE ID != '1' ORDER BY display_name"); foreach($authors as $author) { echo ""; echo "<a>ID; echo "\">"; echo get_avatar($author->ID); echo "</a>"; echo ''; echo "<a>ID; echo "\">"; the_author_meta('display_name', $author->ID); echo "</a> - <strong>"; the_author_meta('city', $author->ID); echo ","; the_author_meta('state', $author->ID); echo "</strong>"; the_author_meta('phone', $author->ID); //the_author_meta('description', $author->ID); //echo ""; //the_author_meta('user_url', $author->ID); echo ""; echo ""; } }I also wanted this to appear just on my contacts page, so, in the sidebar, i added my code like this:
post_parent == '20' ) { echo "Contacts"; echo ""; if (function_exists('contributors')) contributors(); echo ""; } else {} ?>Thanks again, you’ve helped cut out a tonne of unessecary plugins!