WordPress hack: Show your top contributors without a plugin
Simply paste this code where you want your top contributors to be displayed. Note that this code use the mysql_* functions instead of the $wpdb object. This is not the better way to do this, but it do the trick
<?php include($_SERVER['DOCUMENT_ROOT']."/wp-config.php"); mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die(mysql_error()); mysql_select_db(DB_NAME) or die(mysql_error()); $sql = "SELECT ".$table_prefix.users.".".user_login.",count(*)\n" . "FROM ".$table_prefix.posts.",".$table_prefix.users."\n" . "WHERE ".$table_prefix.posts.".".post_parent."=0 and ".$table_prefix.posts.".".post_author."=".$table_prefix.users.".".ID."\n" . "Group by ".$table_prefix.users.".".user_login."\n" . "Order by count(*) DESC\n" . "Limit 0,10"; $result = mysql_query($sql) or die(mysql_error()); echo "\n"; echo "<ul>"; while($row = mysql_fetch_array($result)) { echo "<li><strong>"; echo $row['user_login']; echo "</strong> "; echo "("; echo $row['count(*)']; echo ")</li>"; } echo "</ul>"; ?>
This recipe has been submitted by Sidou. Do not hesitate to send me your recipes if you want them to appear on my site!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!