MyBB Community Forums

Full Version: Variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I've been out of luck finding the variables for total amount of posts, total amount of threads, newest member, and amount of members. I've looked over the stats but I'm aware those variables will not work in the ordinary template I am using.

Any suggestions?
$stats['numposts']      = number of posts
$stats['numthreads']   = number of threads
$stats['numusers']      = number of users
$stats['lastuid']           = newest member (uid)
$stats['lastusername'] = user name newest member

When you want to use this in e.g. a plugin script, you must add:

global $cache;
$stats = $cache->read('stats');
(2015-08-29, 06:35 PM)Ad Bakker Wrote: [ -> ]$stats['numposts']      = number of posts
$stats['numthreads']   = number of threads
$stats['numusers']      = number of users
$stats['lastuid']           = newest member (uid)
$stats['lastusername'] = user name newest member

When you want to use this in e.g. a plugin script, you must add:

global $cache;
$stats = $cache->read('stats');

Just as I thought. Wrapped it in the {} so it can be placed inside the templates and nothing was shown. Literally, the result of adding it was nothing.
{$stats['numposts']}
{$stats['numthreads']}
{$stats['newest_user']}
{$stats['numusers']}
(2015-08-29, 06:47 PM)Wires Wrote: [ -> ]Just as I thought. Wrapped it in the {} so it can be placed inside the templates and nothing was shown. Literally, the result of adding it was nothing.

Generally the variables are only available in index.php, and hence in templates that are evaluated from there, when they are evaluated after the line:
$stats = $cache->read('stats');

is executed.
(2015-08-29, 06:51 PM)Sazze Wrote: [ -> ]{$stats['numposts']}
{$stats['numthreads']}
{$stats['newest_user']}
{$stats['numusers']}

This doesn't seem to work in templates as I already said.
(2015-08-29, 06:51 PM)Ad Bakker Wrote: [ -> ]
(2015-08-29, 06:47 PM)Wires Wrote: [ -> ]Just as I thought. Wrapped it in the {} so it can be placed inside the templates and nothing was shown. Literally, the result of adding it was nothing.

Generally the variables are only available in index.php, and hence in templates that are evaluated from there, when they are evaluated after the line:
$stats = $cache->read('stats');

is executed.

I am trying to execute these variables within the portal templates.
(2015-08-29, 07:17 PM)Wires Wrote: [ -> ]I am trying to execute these variables within the portal templates.

When the portal stats setting:

AdminCP -> Configuration (Settings) -> Portal Settings -> Show forum statistics

is set to "yes", the variables are evaluated. But then it depends when your templates are evaluated, this must be after line 195 of portal.php. When your templates are evaluated before that, you must make a core change or handle it with a plugin.

Which templates are we talking about?
(2015-08-29, 07:29 PM)Ad Bakker Wrote: [ -> ]
(2015-08-29, 07:17 PM)Wires Wrote: [ -> ]I am trying to execute these variables within the portal templates.

When the portal stats setting:

AdminCP -> Configuration (Settings) -> Portal Settings -> Show forum statistics

is set to "yes", the variables are evaluated. But then it depends when your templates are evaluated, this must be after line 195 of portal.php. When your templates are evaluated before that, you must make a core change or handle it with a plugin.

Which templates are we talking about?

The stats are displaying fine on the portal template. However, I'm trying to display the stats on the portal_latestthreads template.
(2015-08-29, 07:58 PM)Wires Wrote: [ -> ]The stats are displaying fine on the portal template. However, I'm trying to display the stats on the portal_latestthreads template

Is this a plugin template? Then the plugin script that evaluates the template should contain the line (at the start):

global $stats;
(2015-08-29, 08:35 PM)Ad Bakker Wrote: [ -> ]
(2015-08-29, 07:58 PM)Wires Wrote: [ -> ]The stats are displaying fine on the portal template. However, I'm trying to display the stats on the portal_latestthreads template

Is this a plugin template? Then the plugin script that evaluates the template should contain the line (at the start):

global $stats;

This is not a plugin. To make this easier I'm now trying to add {$stats} to the index template. The error is now "Array". Any idea? Seems like I can't place any variable on the front page of the forum, in a side bar by the way.
Pages: 1 2