Support » Fixing WordPress » Top authors
Top authors
-
I came across a blog powered by wordpress displaying the top 5 authors in the menu. Is there a plugin available for this? I would like to have their usernames displayed with a link to their website if entered when they registered. Thank you.
-
I have found tags in the template tags section of wordpress so is there a way to have a tag that displays the list of users with a link to their website instead of a link to their articles? Here is the 2 tags I have found for what I need. I just don’t know how to put them together.
List of authors:
<ul>
<?php wp_list_authors(); ?>
</ul>Authors URL:
<?php if (get_the_author_url()) { ?><a href="<?php the_author_url(); ?>"><?php the_author(); ?></a><?php } else { the_author(); } ?>
get_the_author_url()
needs to be called from within The_Loop, so it’s likely not what you want.There might be a plugin to accomplish what you want, but I don’t know of one.
Here’s some tricks I picked up from reading Kaf’s code:
Seemes to work okay in 2.0.1 version of the
wp-content/themes/default/sidebar.php
.<h2>Link list of authors:</h2>
<ul>
<?php
$order = 'user_nicename';
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
foreach($user_ids as $user_id) : // start authors' profile "loop"
$user = get_userdata($user_id);
?>
<li><?php echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; ?><br /></li>
<?php
endforeach; // end of authors' profile 'loop'
?>
</ul>
You are a genius Michael 🙂 Your code is working just like I wanted it to. Thank you very much.
Genius at copying Kaf’s code is more like it!
Glad it worked.
Hi Micheal, this method just display a list of authors. Is there any way to display a list of 5 top authors in an descend order ? Much appreciated for your help !
To list the users with the “top” posts, and display them in posting order, change this part of the code MichaelH used above:
<?php
$order = 'user_nicename';
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
foreach($user_ids as $user_id) : // start authors' profile "loop"
$user = get_userdata($user_id);
?>to this:
<?php
$order = 'postcount';
$limit = '5';
$usersinfo = $wpdb->get_results("SELECT $wpdb->users.ID as ID, COUNT(post_author) as postcount FROM $wpdb->users LEFT JOIN $wpdb->posts ON $wpdb->users.ID = $wpdb->posts.post_author WHERE post_type = 'post' GROUP BY post_author ORDER BY $order DESC LIMIT $limit");
foreach($usersinfo as $userinfo) : // start authors' profile "loop"
$user = get_userdata($userinfo->ID);
$user->postcount = $userinfo->postcount;
?>Change the
$limit
value to the # of users you want to show. To display post count for a user, just use:<?php echo $user->postcount; ?>
- The topic ‘Top authors’ is closed to new replies.