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:
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_list($number = 10) { $u = array(); $authors = get_users_of_blog(); if ($authors) { foreach ($authors as $author) { $post_count = get_usernumposts($author->user_id); $u[$author->user_id] = $post_count; } arsort($u); $i = 0; echo '<ul>' . "\n"; foreach ($u 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>' . "\n"; } } } 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.
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/
I prefer don’t use plugins if possible do something without them.