TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,231
  • Total Topics: 21,353
  • Online today: 606
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 587
  • Total: 587

Statistic in BANNER (index.template.php)

Started by Ruscon, October 03, 2008, 06:38:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ruscon

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


Ruscon

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: ?

IchBin

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.

Ianedres

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

This website is proudly hosted on Crocweb Cloud Website Hosting.