How to Display an Author List with Avatars in WordPress Contributors Page

While working on a client’s website, we realized that the built-in function for listing authors was not enough. We showed you how to display all authors from your site, but that method was only good if you want a simple list to display in your sidebar. If you want to create a more content-rich and useful contributors page, then that function is useless.

In this article we will show you how you can create a contributors page which will display a list of authors with avatars or userphoto and any other information that you like. This tutorial is an intermediate level tutorial.

First thing you need to do is create a custom page using this template.

Then you will need to open functions.php file in your themes folder and add the following code:

01 function contributors() {
02 global $wpdb;
04 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
06 foreach($authors as $author) {
07 echo "<li>";
08 echo "<a href=\"".get_bloginfo('url')."/?author=";
09 echo $author->ID;
10 echo "\">";
11 echo get_avatar($author->ID);
12 echo "</a>";
13 echo '<div>';
14 echo "<a href=\"".get_bloginfo('url')."/?author=";
15 echo $author->ID;
16 echo "\">";
17 the_author_meta('display_name', $author->ID);
18 echo "</a>";
19 echo "</div>";
20 echo "</li>";
21 }
22 }

By adding this function you are telling WordPress to create a function that will display author’s name, and author’s avatar. You can change the avatar to userphoto plugin setting by simply changing the following line:

1 echo get_avatar($author->ID);

and replacing it with:

1 echo userphoto($author->ID);

You can add more features to this function such as displaying author URL and other information from the profile by following the structure used.

You would also need to add the following lines to your CSS file:

01 #authorlist li {
02 clear: left;
03 float: left;
04 margin: 0 0 5px 0;
05 }
07 #authorlist img.photo {
08 width: 40px;
09 height: 40px;
10 float: left;
11 }
13 #authorlist div.authname {
14 margin: 20px 0 0 10px;
15 float: left;
16 }

Once you are done adding the function, now you would need to call it in your page-template. Open the contributors.php file or whatever you name the file. Follow the same page template as your page.php and in the loop, just add this function instead of displaying the content:

1 <div id="authorlist"><ul><?php contributors(); ?></ul></div>

This will provide you with a more content-rich contributors page. This trick is excellent for Multi-Author blogs.

Now here is an example of how we used it:

Example of a Contributors Page with Author List and other Info

If you want to have a contributors page with information like displayed in the example above, you will need to make a few changes to the original function. We have an example code that will get you exactly everything displayed in the image above.

01 function contributors() {
02 global $wpdb;
04 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY display_name");
06 foreach ($authors as $author ) {
08 echo "<li>";
09 echo "<a href=\"".get_bloginfo('url')."/author/";
10 the_author_meta('user_nicename', $author->ID);
11 echo "/\">";
12 echo get_avatar($author->ID);
13 echo "</a>";
14 echo '<div>';
15 echo "<a href=\"".get_bloginfo('url')."/author/";
16 the_author_meta('user_nicename', $author->ID);
17 echo "/\">";
18 the_author_meta('display_name', $author->ID);
19 echo "</a>";
20 echo "<br />";
21 echo "Website: <a href=\"";
22 the_author_meta('user_url', $author->ID);
23 echo "/\" target='_blank'>";
24 the_author_meta('user_url', $author->ID);
25 echo "</a>";
26 echo "<br />";
27 echo "Twitter: <a href=\"http://twitter.com/";
28 the_author_meta('twitter', $author->ID);
29 echo "\" target='_blank'>";
30 the_author_meta('twitter', $author->ID);
31 echo "</a>";
32 echo "<br />";
33 echo "<a href=\"".get_bloginfo('url')."/author/";
34 the_author_meta('user_nicename', $author->ID);
35 echo "/\">Visit&nbsp;";
36 the_author_meta('display_name', $author->ID);
37 echo "'s Profile Page";
38 echo "</a>";
39 echo "</div>";
40 echo "</li>";
41 }
42 }

This code is utilizing User Photo plugin. The twitter field is being displayed using the trick we mentioned in the article How to Display Author’s Twitter and Facebook in the Profile page.

The CSS for example would look like:

01 #authorlist ul{
02 list-style: none;
03 width: 600px;
04 margin: 0;
05 padding: 0;
06 }
07 #authorlist li {
08 margin: 0 0 5px 0;
09 list-style: none;
10 height: 90px;
11 padding: 15px 0 15px 0;
12 border-bottom: 1px solid #ececec;
13 }
15 #authorlist img.photo {
16 width: 80px;
17 height: 80px;
18 float: left;
19 margin: 0 15px 0 0;
20 padding: 3px;
21 border: 1px solid #ececec;
22 }
24 #authorlist div.authname {
25 margin: 20px 0 0 10px;
26 }

You can display more information if you like by using the advanced code as your guide.

Source of this Function


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s