XF 1.5 How to get the "total online users count" globally

maxicep

Active member
Hello

I want to get "total online users now count" to my header in xenforo.
Also, i wanna get the total online user count to my custom portal software too.

Is there any add-on for that ? Or how is possible ?

Thanks
 
Last edited:
Hello,

Unless I am mistalen, the number of total users online now in the sidebar is included in xenforo. If that is not what you meant, can you please screenshot it?
 
Add this to the sidebar_online_users template:
Code:
<xen:container var="$onlineUsers">{$onlineUsers.total}</xen:container>

You can then call it in the PAGE_CONTAINER template using:
Code:
{xen:number $onlineUsers}

But it will only work for pages which load the sidebar_online_users template.
It's really going to require custom development or an add-on to make it available everywhere.
 
Add this to the sidebar_online_users template:
Code:
<xen:container var="$onlineUsers">{$onlineUsers.total}</xen:container>

You can then call it in the PAGE_CONTAINER template using:
Code:
{xen:number $onlineUsers}
And how is possible the call this counts in another php blog software ?
 
Thank you for your help, i will go a custom development for that which uses text file cache.

Then for my portal software, i will get variables (current online visitors) from a text file in hosting that how many visitors online.
 
How do you get the total online users outside Xenforo so the php file reads from XF database

Here's how @LPH does it with Xenword to get the number of threads and posts, but I am unable to get it for the total of Currently Online users


PHP:
        echo '<dl class="pairsJustified discussions"><dt>Discussions:</dt><dd>' . XenForo_Locale::numberFormat( $total_counts['discussions'] ) . '</dd></dl>';
        echo '<dl class="pairsJustified messages"><dt>Messages:</dt><dd>' . XenForo_Locale::numberFormat( $total_counts['messages'] ) . '</dd></dl>';

I tried with this but it doesn't work, it just shows, Currently Online: 0
PHP:
        echo '<dl class="pairsJustified messages"><dt>Currently Online:</dt><dd>' . XenForo_Locale::numberFormat( $total_counts['total_online_users'] ) . '</dd></dl>';

There has to be a way how to call this number, because the xen:number phrase string for this is already present in sidebar_online_users template
total-online.webp

<div class="footnote">
{xen: phrase online_now_x_members_y_guests_z_robots_a, 'total={xen:number $onlineUsers.total}', 'members={xen:number $onlineUsers.members}', 'guests={xen:number $onlineUsers.guests}', 'robots={xen:number $onlineUsers.robots}'}
</div>
 
Last edited:
First, create the model. Second use the getBoardTotalscounter() method. Finally, pull from the array.

PHP:
       /** @var $countersModel XenForo_Model_Counters */
        $countersModel = XenForo_Model::create( 'XenForo_Model_Counters' );
        $total_counts = $countersModel->getBoardTotalsCounter();
        echo '<div class="stats">';
        echo '<dl class="pairsJustified discussions"><dt>Discussions:</dt><dd>' . XenForo_Locale::numberFormat( $total_counts['discussions'] ) . '</dd></dl>';
        echo '<dl class="pairsJustified messages"><dt>Messages:</dt><dd>' . XenForo_Locale::numberFormat( $total_counts['messages'] ) . '</dd></dl>';
        echo '<dl class="pairsJustified members"><dt>Members:</dt><dd>' . XenForo_Locale::numberFormat( $total_counts['users'] ) . '</dd></dl>';
 
Top Bottom