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

This code is no longer up-to-date. Please check out “An Even Better Author List in WordPress” for a better approach.

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 "
  • "; echo "ID; echo "\">"; echo get_avatar($author->ID); echo ""; echo '"; echo "
  • "; } }

    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);

    Share this:

    Email
    Facebook
    Twitter
    Pinterest
    Pocket

    Premium Themes for WordPress

    Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

    Use this WordPress website builder to build powerful websites in no time for your or your clients.

    WordPress Hosting

    WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

    Bluehost – providing quality web hosting solutions since 1996.

    About the author

    Picture of Luke Perrie

    Luke Perrie