Subscribe to RSS Follow me on Twitter
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

230112'
Written by Dimox

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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.

Category: WordPress
Tagged with: ,

Cоmmеnts (6):

  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?

    • 4

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

      • 5

        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. :)

Lеаvе а соmmеnt





Tag Cloud