MyBB Community Forums

Full Version: Custom Statistics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi again,

In Board Statistics, there are 3 sub stats:
  • Who's Online
  • Birthdays
  • Board Statistics
I need to add one additional sub statistic.


I tried editing following :
index.php
//added
$templatelist .= ",index_customstats";

$customstats = '';
if($mybb->settings['showindexstats'] != 0)
{
	eval('$customstats = "'.$templates->get('index_customstats').'";');
}

Home » Template Sets » Default Templates » Edit Template: index_boardstats
<tbody style="{$collapsed['boardstats_e']}" id="boardstats_e">
{$whosonline}
{$birthdays}
{$forumstats}
{$customstats}
<tr>

And added a template under Index Page Templates, named index_customstats
<tr><td class="tcat"><span class="smalltext"><strong>Custom Statistics</strong></span></td></tr>
<tr>
<td class="trow1"><span class="smalltext">
Some info<br />
Some info<br />
More info
</span>
</td>
</tr>


But Custom Statistics does not appear on index page. Any guidance pls?
It should works if you call your template before the $boardstats is called.
Also, to cache your template, you should register your additional template before the global.php is called.
(2015-09-29, 05:53 PM)RateU Wrote: [ -> ]It should works if you call your template before the $boardstats is called.
This worked, Thank you very much once again man.


(2015-09-29, 05:53 PM)RateU Wrote: [ -> ]Also, to cache your template, you should register your additional template before the global.php is called.

By this statement, do you mean:
define('THIS_SCRIPT', 'index.php');

$templatelist = "index,index_whosonline,index_whosonline_memberbit,forumbit_depth1_cat,forumbit_depth2_cat,forumbit_depth2_forum,forumbit_depth1_forum_lastpost,forumbit_depth2_forum_lastpost,forumbit_moderators";
$templatelist .= ",index_birthdays_birthday,index_birthdays,index_logoutlink,index_statspage,index_stats,forumbit_depth3,forumbit_depth3_statusicon,index_boardstats,forumbit_depth2_forum_lastpost_never,forumbit_depth2_forum_viewers";
$templatelist .= ",forumbit_moderators_group,forumbit_moderators_user,forumbit_depth2_forum_lastpost_hidden,forumbit_subforums,forumbit_depth2_forum_unapproved_posts,forumbit_depth2_forum_unapproved_threads";

$templatelist .= ",index_customstats";

require_once './global.php';
and
$customstats = '';
if($mybb->settings['showindexstats'] != 0)
{
    $stats = $cache->read('stats');
    eval('$customstats = "'.$templates->get('index_customstats').'";');
}
Yep, something like that.

What I meant by this
(2015-09-29, 05:53 PM)RateU Wrote: [ -> ]call your template
is
$customstats = '';
if($mybb->settings['showindexstats'] != 0)
{
    eval('$customstats = "'.$templates->get('index_customstats').'";');
} 

What I meant by this
(2015-09-29, 05:53 PM)RateU Wrote: [ -> ]$boardstats
is
eval('$boardstats = "'.$templates->get('index_boardstats').'";');
or about line #312 - #328 (by default).

What I meant by this
(2015-09-29, 05:53 PM)RateU Wrote: [ -> ]to cache your template, you should register your additional template
is
$templatelist .= ",index_customstats";


And what I meant by this
(2015-09-29, 05:53 PM)RateU Wrote: [ -> ]global.php is called.
is
require_once './global.php';

MyBB cache the templates in global.php, so we should register any custom templates before it is called or included, otherwise, it'll adds additional query to the page.

BTW, is there any reason why you prefer editing core file than using a plugin?
I am unaware of such a plugin that adds additional stats this way. There are few plugins out there that appends boardstats but I needed to add separate stats.

I also am a MyBB noob to even think of making my own plugin for this purpose.