Top X Node Authors

Last modified: July 4, 2009 - 00:45

<?php
$users
= db_query("SELECT COUNT(n.nid) count, u.name, u.uid FROM {users} u LEFT JOIN {node} n ON u.uid = n.uid WHERE u.uid != 0 AND u.uid != 1 AND n.uid = u.uid AND u.status = 1 AND n.status = 1 GROUP BY n.uid ORDER BY count DESC LIMIT 10");

$output = "<ul>";
while (
$user = db_fetch_object($users)) {
 
$output .= "<li>" . l($user->name, drupal_get_path_alias("user/{$user->uid}")). " ($user->count)</li>";
}
$ouput .= "</ul>";
echo
$output;
?>

To change the number of users shown, simply change the "LIMIT 10" clause to whatever amount of users you wish to display.

Currently excludes both the administrative (user 1) and anonymous user (user 0), blocked users, and unpublished posts. You can adjust the WHERE clause to change this as desired.

Can easily be modified for different content types by adding various combinations of AND n.type = 'content-type' or AND n.type != 'content-type' to the WHERE clause.

 
 

Drupal is a registered trademark of Dries Buytaert.