Making a list of blog authors : get_users_of_blog and get_userdata
Following on from a previous post on how to make author profile pages for WordPress, Jabril and a couple of others asked how to make a page listing all the authors of a blog, with bio information and a photo. Here's how to do that.
Some things before we start:
- You'll need to adapt this for your own theme (probably): e.g. you might need to add get_sidebar() in the appropriate place, or whatever.
- You will need to save this to your theme's folder and then make a new page utilising this template. Just uploading it to the theme folder is not enough!
- By default, this code shows *all* users of your blog, whether they're admins, subscribers, or some rank in between. If you want to show, for example, only people who have actually published posts, you'll need to do some more filtering.
- If you haven't filled in the user profile information, it won't show up. (This may seem obvious...)
Here's the basic code:
<?php
/*
Template Name: Author List
*/
get_header();
$blogusers = get_users_of_blog(); //gets registered users
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id); //gets the actual data about each user
//do stuff
}
}
else { echo "Bizarrely, your blog appears to have no users. Something weird has happened."; }
get_footer();
?>
get_userdata can access any of the information about each user in the users and usermeta tables. Some of the more useful information will be:
- display_name
- first_name
- last_name
- user_email
- user_url
- user_registered (the date)
- description (the bio text)
- user_level (e.g. 10 is an admin)
There's a full list in the Codex.
So for example, to show a user's display name, clickable url, biography and whether they're an admin, replace the //do stuff line with:
echo $user->display_name." <a href=\"".$user->user_url."\">".$user->user_url."</a><p>".$user->description."</p>";
if ($user->user_level == 10) {echo "<b>Admin</b>"; }
Including pictures
The easiest way to show a photo for each user is (as always with WordPress) to use Gravatar. You can easily call up the Gravatar relating to each user's email address with the normal get_avatar function:
echo get_avatar( $user->user_email, $size = 'xx', $default = 'yyy' );
where xx is the size in pixels of the square image (the maximum is 512) and yyy is the URL of the default avatar you want to use if this email address doesn't have an image in Gravatar.
Activating the page
Read this bit! This is what most people don't do, and chief cause of "it doesn't work"!
- Once you've decided what information you want in your author list and have edited the code above, save it as a .php file; call it authorlist.php or something you'll recognise.
- Upload it to your theme folder.
- Then go to Admin > Pages and make a new page. Give it a title; you don't need to give it any other content.
- Change the Page Template to Author List.
- Publish.
Just uploading the template to your theme folder is not enough; you need to publish an actual page to have the author information show up on your blog.
Need help?
If you need help implementing this for your own blog, leave me a comment: I'll need a link to your blog and a note of what theme you're using. "I have a custom theme" is not enough information for me to figure out why you might be having difficulties
Posted by Sue on July 21, 2009 in WordPress.








Thanks for the code!
I'm trying to show an active email address. I can show it by editing the code for user_url to user_email, but am having trouble modifying the link. Can you tell me how to change the link to a mailto?
Hi Csleh,
You'd need to change the name/link line to
echo $user->display_name.' <a href="mailto:'.$user->user_email.'">'.$user->user_email.'</a>';Awesome thank you!
This is really cheeky, but do you know how (or have seen resources) to add cimy custom fields? That plugin info is no help.
It's not a plugin I've ever used: I guess you've visited Marco's page here?
http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-extra-fields/
or the plugin directory page (plus linked support threads) here
http://wordpress.org/extend/plugins/cimy-user-extra-fields/
Alternatively, mail me or leave me a comment with what you're trying to do, and I'll see if I can help. Unless you're getting massively complicated with custom fields, plugins to manage them aren't always necessary.
Sue should immediately open an WPEO, i.e. Wordpress Emergency Office, and we should ask our sickness insurance companies to reimburse her fee. Good job Madame !!
PMSL. Thanks Kalvin
it is really nice and tricky. quiet useful for blog commenting
This plug-in works great, thank you!
Is there any way to sort the list of authors? By first name, last name, number of posts...anything like that?
Thanks,
Terri Z
Hi Terri,
The short answer, “yes”. The slightly longer answer – actually, I think I’d do that in a completely different way, with a custom select query. New blog post coming up…
Hi Sue,
I was just checking back to see if you had posted anything about ordering the list of authors. If so, can you please point me to that blog post?
Thanks!
Terri Z
ok so i am really new at this coding thing and i really need to have a page with authors bio's and pics One on top of the other. The theme i am using is Berita Business 1.6 by BizzArtic Thanks so much ^_^
You can use the code above to do that, David. Just change the variables as you need them.
Wonderful!
Although I know practically NOTHING about php, by following your instructions I was able to produce this author's page
I would like to format it a little, perhaps making the author's names appear in bold and putting some spacing between the profiles.
I started learning Python sometime back, and although I enjoyed the challenge, I was lacking motivation because I didn't really see any particular use for it in what I am doing. It seems that learning php would be a much more useful for what I spend a lot of time doing - blogging.
Well done, Jimmy - although I'm not seeing a page on your link - you did remember to publish it?
If you're going to do a lot of work with WP, then PHP is obviously the way to go. If you've learned Python, you shouldn't have any difficulties.
Hi Sue,
Yes I did publish the page, but then made it private again (because the author bios aren't quite finished). I thought that would just make it "unlisted" - so you'd be able to see it, given the link I provided.
OK, I am taking your advice about php.
By the way, my *potential* employer uses Drupal, would php be useful here too?
Thanks,
Jimmy.
Hi again Jimmy - no, making it private/draft/unpublished means that non-signed-in members of your blog can't read it.
And yes, PHP will be useful with Drupal - good luck
Awesome tutorial, Sue! My only question - how would one make the authors name a link to their individual profile?
I'm using a theme called "Simplified2" that I've already modified quite a bit.
Thanks!
Brett
Brett, you got mail
This is a great post, thank you so much. I have it mostly working but I have kind of different situation - I've created a number of custom user meta fields that I would normally call like this:
get_the_author_meta('industry', $user_id);
I have a custom meta field for 'industry' and for 'company'. What I want to do is display 'company' when 'industry' = 'Photography', for example.
This is what I've added to your code within the 'foreach' section:
if ($user->industry='Photography') {
echo "$user->company";
}
This correctly prints the company (which is great because I've never gotten this far before) but it *doesn't* select for industry='Photography', it just prints every company. I assume there's something wrong with my 'if' statement. Can you make any suggestions?
Hi Sue!
THANK YOU!!! I have been searching and trying different things to get a listing of members on my site. I'm talking HHHHHOOOOOUUUURRRRSSSSSS of work.) This is the only one I could get to work! Ta da! I'd like to limit the number of members per page. (is that pagination??)and sort alphabetically. -Limit the number of listings more than the alpha part. Can you point me in the right direction?
Again... a huge THANK YOU!
How do I embed HTML on the code, say I want to color each user differently?
Zeal, that would be part of the "do stuff" line as above. The point of the code is to automate it, so if you want to pick a different colour for each user, you might be better just making a manual list.
Hello Sue,
This is fantastic. Easy to follow, and took me less than an hour to implement (a miracle for me - php is pretty much greek to me).
I do have one request - I'd like to make the author names a link to their normal page, the way they are with the_author_post_link tag in wp templates. How do I do that? I saw this request among your comments, but I think you sent a reply via email. Could you possibly post it here as well?
Thank you!
I got the link to the author pages sorted out, but I have another question: how do I exclude users from this list? I don't want subscribers, contributors or the admin to show up here.
Here's my code so far:
user_id); //gets the actual data about each user
echo "";
echo get_avatar( $user->user_email, $size = '80' );
echo "" ;
echo "ID.">";
echo $user->display_name;
echo " | ";
echo $user->user_email;
echo "".$user->description."";
}
}
?>
Check user_level before you output anything, so you only output authors and editors (or whatever levels you want).
I've go this completely working. Thanks a million!!
The only thing that I've noticed is I've set this to Authors (user level 2) but it still shows all the user levels. Obviously because they're also user level 2. How do I exclude them?
And this has been asked as well. How do I sort them alphabetically?
Thanks in advance!!
Hi, great tutorial, thanks!
I also would like to know how to sort the list in alphabetical order. I have searched your website, but can't find the "next" article. Could you please point me/us in the right direction?
Thanks!