TinyPortal
Development => Support => Topic started by: Ruscon on October 03, 2008, 06:38:00 PM
Basically I added the stats block in TP which made me wanna put that info on other places on site. So I had this idea of putting some statistic in the banner of the page. Tried to look source for the stats block and I found these:
<li>'.$txt['tp-guests'].': '.$online['guests'].'</li>
<li>'.$txt['tp-total'].': '.$online['total_users'].'</li>
None of thoose works if I put them in index.template.php, anyone can explain to me why? I'd like them to work everywhere just like the TP statsbox does. Adding them to index.template.php would make them appear everywhere since it's in the banner ;D
Please read the Posting Guidelines.html (http://www.tinyportal.net/index.php/topic,581)
Link to my site: Local
SMF version: 1.1.6
TP version: 1.0.5 beta
Theme name and version: DarkBreak
Mods installed: TP 1.0.5 beta
Related Error messages: ?
If you look at the code that you pulled that from.
$online = ssi_whosOnline('array');
echo $txt['tp-users'].': '.$online['num_users']. '
</li>
<li>'.$txt['tp-guests'].': '.$online['guests'].'</li>
<li>'.$txt['tp-total'].': '.$online['total_users'].'</li>
<li style="width: 100%; ' , $online['num_users']>14 ? 'height: 23ex;overflow: auto;' : '' ,'">';
You'll see that at the top, it uses the ssi_showOnline() function assigning it to the $online variable. Since you are adding that to the block without calling the function or declaring $online global, you are most likely getting Undefined index errors in your log.
I'm not sure if just adding global $txt, $online to the top of your PHP code will work. If not, you'll just need to call the function like it does in the code I posted.
A general understanding of the php scope for variables would assist you, Ruscon.
It is great that you are wanting to customize your site and looking at the code shows great initiative. But sometimes merely copying the code strings from one script to another script isn't enough, as SMF assigns variables only as needed in each module to reduce memory use on the server. (There are some very large arrays produced per visitor.) You may need to call a module's specific function to load the variable values first.
I'm not trying to be condescending; this is why changing some things can be difficult or otherwise a walk through SMF's structure just to get something so minor out of it.
PHP Scope: http://www.php.net/manual/en/language.variables.scope.php
SMF Functions: http://support.simplemachines.org/function_db/index.php