1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Questions and Support' started by maxicep, Mar 6, 2016.

  1. maxicep

    maxicep Active Member


    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 ?

    Last edited: Mar 6, 2016
  2. wang

    wang Well-Known Member


    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?
  3. maxicep

    maxicep Active Member

    My mistake, i mean in header not sidebar sorry.

    I need get the numbers globally in header and my portal blog software both.
  4. wang

    wang Well-Known Member

    Can you please screenshot the places?
  5. Brogan

    Brogan XenForo Moderator Staff Member

    Add this to the sidebar_online_users template:
    <xen:container var="$onlineUsers">{$onlineUsers.total}</xen:container>
    You can then call it in the PAGE_CONTAINER template using:
    {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.
    maxicep and eva2000 like this.
  6. maxicep

    maxicep Active Member

    And how is possible the call this counts in another php blog software ?
  7. Brogan

    Brogan XenForo Moderator Staff Member

  8. Melvin Garcia

    Melvin Garcia Member

  9. maxicep

    maxicep Active Member

    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.
  10. valdet

    valdet Active Member

    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

            echo '<dl class="pairsJustified discussions"><dt>Discussions:</dt><dd>' XenForo_Locale::numberFormat$total_counts['discussions'] ) . '</dd></dl>';
    '<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
            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

    <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}'}
    Last edited: Apr 30, 2017
  11. LPH

    LPH Well-Known Member

    First, create the model. Second use the getBoardTotalscounter() method. Finally, pull from the array.

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

Share This Page