MyBB Community Forums

Full Version: Where is {$users} located?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I would like to add my own variables as for example {$users} is. In which file are they located?

Thank you in advence!
Where do you want to add them? In templates?
Yeah, in templates.
It depends on which template you want. For example, if you want to use that var in a thread, you have to add the var in the showthread.php file (or in /inc/functions_post.php).
To be exact - I would like to make my own table at the bottom of forums showing TOP 10 of some users statistics (wanna make mine instead of using something ready to install). So yeah, it will have to be displayed on the main page of forums. If I am not mistaken I have to put my code into forumdisplay.php yes? And my function will be called by for example {$top10}?
Yes you're right.
You don't have to create a function. You have to add your piece of code before the creation of the template (eval("\$forums = \"".$templates->get("forumdisplay")."\";"); )
Anyway, you can create a plugin and use the hook forumdisplay_end.. (Which I prefer instead of editing the files)
Okay, not that hard I guess. I have one further question tho. If I need to get data from database on my own and I want it to be displayed in my {$top10} variable where should I place the php code for getting data from db?

function top10(){
       global $templates, $mybb, $details, $top10;
    
    // if the plugin setting isn't enabled then exit
    if($mybb->settings['top10_enabled'] != 1)
        return;
    
	$top10 = "<div class=\"statsmenu\"><span class=\"top10text\">Top10</span></div>
				<div class=\"novastats\">
					Top10 - Test
				</div>";

}

For example:
1. Nick - Posts: 999
2. Nick - Posts 151515
3. Nick - Posts 555555
(...)

I wanna get such data in place of "Top10 - Test". I guess I should place MySQL query code above the variable of course but how to put results into place of "Top 10 - Test"?
You can do something like this:
function top10(){
       global $templates, $mybb, $details, $db, $top10;
    
    // if the plugin setting isn't enabled then exit
    if($mybb->settings['top10_enabled'] != 1)
        return;
    
    $top10 = '<div class="statsmenu"><span class="top10text">Top10</span></div>
                <div class="novastats">';
    $query = $db->write_query("your select query");
    while($top10row = $db->fetch_array($query)) {
        $top10 .= $top10row['username'] ." - ". $top10row['postcount'] ." <br />";
    }
    $top10 .= '</div>';

}
Wink