Hi, I'm a web developer and blogger from Russia. My nickname is Dimox.
Sorry for my English, it's not my native. Read more about me and my blog.

WordPress Top Authors List Without a Plugin

WordPress engine allows to create sites with big number of users of different levels. And authors, which have corresponding right, can fill the site content. On such a multi-user sites will be useful to have a list with top authors.

In this post I will show you one of the ways how to display list of the top authors without using a plugin.

You can use the following small function:

function top_authors($number = 10) {
	$uc = array();
	$blogusers = get_users();
	if ($blogusers) {
		echo '<ul>';
		foreach ($blogusers as $bloguser) {
			$post_count = count_user_posts($bloguser->ID);
			$uc[$bloguser->ID] = $post_count;
		}
		arsort($uc);
		$i = 0;
		foreach ($uc as $key => $value) {
			$i++;
			if ($i <= $number) {
				$user = get_userdata($key);
				$author_posts_url = get_author_posts_url($key);
				$post_count = $value;
				if ($post_count > 0) {
					echo '<li><a href="' . $author_posts_url .'">' . $user->display_name . '</a> (' . $post_count . ')</li>';
				}
			}
		}
		echo '</ul>';
	}
}

Paste this function in the functions.php file of your theme and then put the following code in a place of your theme, where you want to see the top authors list:

<?php if (function_exists('top_authors_list')) top_authors_list(10); ?>

10 here is the number of authors you want to show in the list.

That’s all.

As a result you will see the list of top authors with their names and number of published posts. Author’s name is linked to his archive page where is a list of all his posts.

List of top authors is sorted by number of posts.

Cоmmеnts (8):
  1. 1

    Why the unnecessary plugin hate? They’re almost always better than filling up your functions.php…

    http://kovshenin.com/2012/01/plugins-vs-without-a-plugin-3745/

  2. 3

    How would I use Transients API to cache this?

Lеаvе а Соmmеnt

© 2009–2014 Dimox.net  •  Privacy Policy