Saturday, October 10, 2009

MC Sidebar top users code

This code adds the top five users to the sidebar.

In index.php, add the following code;


$user = new User;


$select = "SELECT user_id, COUNT(*) as count ";

$from_where = " FROM " . table_comments . ", " . table_users . " WHERE comment_user_id=user_id GROUP BY comment_user_id";

$order_by = " ORDER BY count DESC ";


$rows = $db->get_var("select COUNT(*) as count $from_where $order_by");

$users = $db->get_results("$select $from_where $order_by LIMIT 0, 5");

$users_table = '';


if ($users) {

foreach($users as $dbuser) {


$user->id=$dbuser->user_id;

$user->user_read();

$user->all_stats();


$main_smarty->assign('user_userlink', getmyurl("user", $user->username));

$main_smarty->assign('user_avatar', get_avatar('large', "", $user->username, $user->email));

//function get_avatar($size = "large", $avatarsource, $user_name = "", $user_email = "", $user_id=""){

$users_table .= $main_smarty->fetch(The_Template . "/topusers_data.tpl");



}

}


$main_smarty->assign('users_table', $users_table);


In the file templates/oioioi/topusers_data.tpl reduce the code to;



Finally in templates/oioioi/sidebar2.tpl add the following code;



Most Commented Users

{$users_table}


This may need further modification in order to fully incorporate CSS


{insert two hour rant about going back to front page here}

No comments:

Post a Comment