I’m trying to do something I assumed would be easy. I assumed wrong. What I want to do is list all the authors of a site on the sidebar, with a link to their respective author page, number of posts written, and gravatar. wp_list_authors doesn’t give me an option to include the gravatar at all. Here is what I have
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
$post_count = count_user_posts($user->ID);
if ($post_count) {
echo '<li>';
echo '<a href="'.get_bloginfo('url').'/author/' . $user->user_nicename . '">'.get_avatar($user->user_email, '36').'</a>';
echo '<a href="'.get_bloginfo('url').'/author/' . $user->user_nicename . '">'.$user->display_name.' ('.$post_count.')</a><li>';
}
}
}
Which works, albeit with two problems:
- I can’t find a way to have them sort by number of posts
- the get_users_of_blog is a depreciated function. I really don’t want to use it.
I was able to create an explode with wp_list_authors, but didn’t have a clue how to extract the data out of it to display in this manner. Help?
To answer your problems:
Sorting by post count
You can collect all the information you need in to an array and sort that array by number of posts , like this:
then change your code a bit like so:
get_users_of_blog is a depreciated
It’s weird because looking at the codex Yes this function is depreciated and you should use
get_users()
which should be shipped with Version 3.1but if you look at wp_list_authors it uses get_users_of_blog() be itself.
Hope this helps.
get_users_of_blog()
may be deprecated per documentation, but it is actually whatwp_list_authors()
uses internally ( source ) and there seems to be no viable alternative available at moment.I see no easy way to customize
wp_list_authors()
the way you want. Can only suggest to reuse code for it in you own function, modification to add gravatar will be minimal.code widget for sidebar: