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;
		$i = 0;
		foreach ($uc as $key => $value) {
			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 (9):
  1. 1

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


  2. 3

    How would I use Transients API to cache this?

    • 4

      Don’t know. I’m not familiar with Transients API.

      • 5
        Mike Kennedy said:

        That’s no problem, I will mess around with it and see if I can get it working.

        Also, when I enabled define('WP_DEBUG', true);, I got a few errors, including two from your code above: get_users_of_blog() and get_usernumposts were deprecated.

        I tried updating them with new WordPress functions but it gave another error. :(

        Could you update the code to include the new functions, please. :)

  3. 9

    Not working this code in my site. I am not sure why happen….

Lеаvе а Соmmеnt

© 2009–2022 Dimox.net  •  Privacy Policy