Doing more with gravatars: Authors template page

We’ve learned how to add an author bio to single posts and revamp our comments with gravatars. Now, it’s time to take this one step farther.
We’re going to create a template page for all of our authors.
This can be useful if you have multiple authors on your site and want to have a page that lists all of them. It’ll let users get to know each author a little before diving into their posts.
Note to my theme users: Of course, all of this stuff is being built right into the development versions of my themes. So, you can look forward to some of this stuff being added in future updates.
Here are the steps required in doing this:
- Give your authors some biographical information from your WordPress dashboard.
- Create a template page to display each author.
- Write a new Page and save it with your new template.
Oh, and you might want to get a gravatar if you don’t have one.
Setting up your authors biographical information
Well, there’s no use in having an authors page without showing some biographical information along with each author.
Log into your WordPress dashboard and click on the “Users” link. From there, you can select any user you want to add information for. Scroll down to the bottom of the screen, and you’ll see a section named “Biographical Info.” Just type whatever you want about yourself or a particular author.

Click “Update Profile” to save this new information. You’ll probably want each author of your blog to write a short blurb that suits them.
Creating the authors template
The first thing we need to do is name our template (very important!) and get the header file. I’ve named this template “Authors” for simplicity.
<?php /*
Template Name: Authors
*/ ?>
<?php get_header(); ?>
Then, we need to set up a basic loop to show the title and content of the page. This way, you can still write a little describing the page later.
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div class="post">
<h2 class="section-header">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>
Now, we can move on to the backbone of this template page, which will show all of our author profiles.
Before we display any information, we need to actually grab the information from the database. I tried to comment this well enough for everyone to reasonably understand what’s going on.
<?php
// Get the authors from the database ordered by user nicename
global $wpdb;
$query = "SELECT ID, user_nicename from $wpdb->users ORDER BY user_nicename";
$author_ids = $wpdb->get_results($query);
// Loop through each author
foreach($author_ids as $author) :
// Get user data
$curauth = get_userdata($author->ID);
// If user level is above 0 or login name is "admin", display profile
if($curauth->user_level > 0 || $curauth->user_login == 'admin') :
// Get link to author page
$user_link = get_author_posts_url($curauth->ID);
// Set default avatar (values = default, wavatar, identicon, monsterid)
$avatar = 'wavatar';
?>
Now for the actual display of the author profiles. We’ll just show each author’s gravatar, display name, and description with the gravatar and display name linked to the author’s archive page.
I’m treating each profile as a post, so I won’t have to add additional CSS to my stylesheet to get them to display properly.
<div class="post">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>">
<?php echo get_avatar($curauth->user_email, '96', $avatar); ?>
</a>
<h3 class="post-title">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?></a>
</h3>
<p>
<?php echo $curauth->description; ?>
</p>
</div>
After that, we just need to close off everything we’ve opened.
<?php endif; ?>
<?php endforeach; ?>
<?php get_footer(); ?>
Just save this file as “authors.php” and drop it in the folder of the theme you’re currently using. You have to save this before moving on to the next step.
Writing our authors page
Once the above is done, all we have to do is create a new page. We go back into our WordPress dashboard and click on “Write > Page” to do this.
Give your new page a title; something like “Authors” might work. Maybe write a few sentences describing what this page is for.
For the most important part (you can’t forget this), find the section titled “Page Template.” There’ll be a drop-down list of page templates to choose from. Select the “Authors” template.

Once that’s done, you can publish your new page and view it on the Web.
Other things you can display
There are a few other things you can display as well. For example, you might want to give a link back to the author’s personal website or show their email. From the author templates page in the WordPress Codex, there’s a list of things you can show (I’m sure they don’t mind me borrowing them for this post).
These things are all configurable from the user profile edit page. Just make sure you use them after the line:
$curauth = get_userdata($author);
from the above code.
$curauth->aim;
$curauth->description;
$curauth->display_name;
$curauth->first_name;
$curauth->ID;
$curauth->jabber;
$curauth->last_name;
$curauth->nickname;
$curauth->user_email;
$curauth->user_login;
$curauth->user_nicename;
$curauth->user_registered;
$curauth->user_url;
$curauth->yim;
Go ahead and create your authors template
This should be a mandatory page for multi-author blogs. It will let your users get to know each author a little better.
As mentioned earlier, I will be incorporating this template into my themes, so if you’re using one of them, look forward to this feature in the next update.
If you need help implementing this, just stop by the support forums because it’s much easier to post code there.
I have done exactly what you have told here. But when I publish the page, I just get the Author as page title and nothing is shown…
Justin it does show other authors detaisl except admin. And I am admin here. I created a new user with riole as author and it is showing the detaisl on the page.
You continue to rock all the time. I’m sure Project M will be the next big WordPress thing soon at this rate.
I don’t think I’ll be making use of this technique anytime soon though. I don’t yet run a multi-author blog, but if I do launch a webcomic with my friend sometime later this year or the next, this will definitely come in useful.
Bookmarked in del.icio.us!
techiezone
I just tried it on another blog, and I can see what you’re talking about. I’ll try to find a fix for this tonight.
BoltClock
Thanks. It looks like there might be a small bug with it right now, but I should have a fix up when I get home from work.
Great tutorial. I run a multi-blog site and I was just thinking of how to display “The Team” that’s behind the site. Now I know, thanks!
IndieLab
Thanks. Let me know when you get it up.
techiezone
For some reason, WordPress wasn’t giving the default user login name of “admin” a user level. It was just blank. Anyway, I updated the code, so it should work now.
Thanks Justin, very useful tutorial. I was eagerly following the series “Doing more with Gravatars” and found them really helpful.
I’m planning to run a multi-author blog next year and this will be a great reference.
$curauth = get_userdata($author);Loll, so do you mean I can display the entire profile contents? Can I add additional hooks such as author posts and author comments on that certain blog?
J Mehmett
The
get_userdata()function is really useful for multi-author blogs. You should be able to add additional author info fairly easily. You might have to look up how to get the number of comments and posts though. I don’t know it offhand.I’m also putting together a widget for this to be included with my themes.
I think I might have one or two more articles that could be useful with gravatars too.
Justin, I like your ideas, man.
The only limit of Implementing Gravatars with WordPress theme might be the sky limit.
nifty. i’m gonna try this out.
Thanks a lot Justin.
Does it matter if I created all the users, because I’m just getting my own picture + bio as many times as I have authors.
Other than that, it seems cool
J Mehmett
I always say, “The only limit is your imagination.”
Jenny
Let me know how it works out for you because I’m implementing this into my themes too.
techiezone
No problem. It looks like you’ve got it working. By pointing that out, you’ve helped me see some other code bugs in my themes that’ll definitely help in future updates.
Thomas
It shouldn’t matter. From everything I can tell, the code should display all users that have any authorial privileges.
Drop your code off in the General Discussion part of the forums, and I’ll have a look at it to see if there’s anything missing.
I’ve done as requested
Great tutorial, I just found your site and will definitely be coming back….I really like your writing style.
I am going to add a link to this article and your site on my blog.
[...] one post I found, he describes how to create an Authors template. He shows how to use it to showcase multiple authors on a blog. He also shows you how to throw [...]
I think there is an extra “=” in the line below:
“// If user level is above 0 or login name is “admin”, display profile”
I removed it and then the admin author showed up for me.
this is an awesome tutorial, but I am using the register plug plugin to extend the user fields, maybe you can show us also how to get those fields into the authors page too? http://wordpress.org/extend/plugins/register-plus/
Also a little help to get some stats about a user would be great, either using built in wp functions, i.e. numer of posts written, or number of comments , anything you can think of. otherwise maybe combining this with the wp stats plugin of lesterchan? http://lesterchan.net/portfolio/programming/php/#wp-stats
There are also another way to show a avatar without using the Gravatar service.
<img src="/wp-content/themes/yourtheme/avatars/.jpg" height="95" width="95" alt="" />Addenum. The avatar file must be named exactly the same as the user login name.
The PHP code was stripped in my last comment.
See: http://www.matblogg.se/avatar_local.jpg
[...] wondering if anyone could help out building a a Thesis Themed bio page for a multi-author blog. This looks like a great framework to start with, but obviously it needs to be styled to fit in nicely [...]
This is fantastic!
I’ve implemented this successfully, but i’m listed right at the top (because i’m the admin). Is there anyway for the admin to be listed with the other authors alphabetically?
Joseph
Check out Author Templates: Using Author Information.
You should be able to change this:
to something like this:
If you need any help with the code though, just stop by new support forums because it’s easier to post code there.