Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to show member count in template?

Hello,

I'm trying to put the total number of users into the default.master.tpl file - The same number that you see when you look up Users in the dashboard.
Any idea on how I can achieve this?

Thanks in advance

Comments

  • peregrineperegrine MVP
    edited August 2014

    there is a plugin.

    http://vanillaforums.org/addon/statisticsfooter-plugin

    or you could use if you want to display list to users.

    http://vanillaforums.org/addon/memberslistenh-plugin

    otherwise if this doesn't answer your question. post a mocked up screenshot of what you want to accomplish.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine you might want de-normalize your counts.

    If every request you are counting you users, that is fine if you don't get much traffic, but if you get a lot of traffic, and have a lot of users, you are a querying for every request it may take its toll. Probably not hugely but why do it anyway?

    You can save the count when users are created and deleted stash it with Gdn::Set('UserCount',$Count);

    You can retrieve it with Gdn::Get('UserCount');

    grep is your friend.

  • thx. @x00 will look into it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @x00 - This sounds good, thank you. We get a lot of traffic so this way would be a lot better I think.

    Any idea how I would put Gdn::Get('UserCount'); into the TPL template as it's not PHP?

  • x00x00 MVP
    edited August 2014

    I know, but if you a not a programmer then it is not trivial. First you will need to hook into the user model to stash an revise the count, through themehooks/pluign then you will need to create a smarty template function to insert it.

    grep is your friend.

  • peregrineperegrine MVP
    edited August 2014

    @x00 said:
    peregrine you might want de-normalize your counts.

    If every request you are counting you users, that is fine if you don't get much traffic, but if you get a lot of traffic, and have a lot of users, you are a querying for every request it may take its toll. Probably not hugely but why do it anyway?

    You can save the count when users are created and deleted stash it with Gdn::Set('UserCount',$Count);

    You can retrieve it with Gdn::Get('UserCount');

    I updated the plugin. didn't hook into usermodel since there are several counts to keep track of,
    but I used the get and set a lasttime interval check. So it updates counts based on a config setting of 60 seconds (which is changeable) , otherwise reads from cache and or usermeta.

    So it is a bit more efficient and doesn't do a sql count on each page load.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.