I am using this code for listing out all authors on the site in my sidebar. It works, except I also need to pull in their Gravatar image. It’s working in a loop on the homepage with this
<?php echo get_avatar( get_the_author_email(), '80' ); ?>
but is there a way I can add it to this list as well?
Also.. I can’t figure out a way to exclude the “Admin” account using this code, is that possible?
Thank you!
<?php
$order = 'user_nicename';
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
foreach($user_ids as $user_id) :
$user = get_userdata($user_id);
?>
<li><?php echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; ?><br /></li>
<?php
endforeach;
?>
Basic setup
Excluding the Admin User
Either check in the
foreach
:or if all other users are subscribers, include the
role
parameter as an argument for the user query:or, if you have but one (or few static) admin user, exclude him/her from the query by id:
Here’s a simple example showing default avatars and lists all users with the role of
author
.use
<?php echo get_avatar( $user->ID, '80' ); ?>
, somewhere inside theforeach
loopIf you’re looking to exclude a particular user, you can use it’s id(
$user->ID
) or username($user->user_login
) or if you want to exclude all the administrators, you can useif(current_user_can('promote_users')) continue;
as the first line of foreach. Check out the reference for more infohttp://codex.wordpress.org/Function_Reference/current_user_can