MyBB Community Forums

Full Version: Plugin unable use variable in index_stats
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hoping someone may be able to help me. I usually just edit  files for a lot of my edits like index.php or whatever however want to start using plugins to clean up the code and make it more manageable.

I'm trying to get the top 5 posters to show in my index_stats template if I add it to index.php and use the variable {$topposter} in my template it works fine however if I use the {$topposter} variable in the template when I use the plugin nothing displays. I'm not sure if it's something to do with my hook?

My hook is 

$plugins->add_hook('index_start', 'statsfinder');

Code is:

function statsfinder()
	global $mybb, $db, $topposter;
	//Top 5 Posters
$topquery = $db->simple_select("users", "username,usergroup,postnum,regdate,uid", "", array(
    "order_by" => 'postnum',
    "order_dir" => 'DESC',
    "limit" => 5
foreach ($topquery as $results) {
			$username = format_name($results['username'], $results['usergroup'], $results['displaygroup']);
			$user_link = build_profile_link($username, $results['uid']);
			$topposter .= sprintf('
			<span style="float:left">%s</span>
			<span style="float:right">%s</span><br />

			',$user_link, my_number_format($results['postnum'])

//top 5 poster end