View Full Version : How to display a count for the number of members in a certain usergroup
mairving
12-20-2012, 03:56 PM
How would I display something along the lines of, "Now home to ### premium members," in a place like the noticebit or somewhere LIKE that in order to catch the eye of non-premium members? Any thoughts or suggestions would be greatly appreciated!
If the premium members belong to a certain usergroup, you could do a query in a plugin and get the count, then use the value in a template. Also, unless you really want it to update as soon as someone else joins, you could put it in a scheduled task and write it to the datastore, so that it won't add a query to each page load. So maybe something like:
$premium_gid = X;
$result = $vbulletin->db->query_first_slave("SELECT COUNT(*) AS members FROM " . TABLE_PREFIX . "user WHERE usergroupid=$premium_gid");
if ($result)
{
build_datastore('premium_members', $result['members']);
}
Maybe using hook cron_script_cleanup_hourly. Then in another plugin on init_startup:
$new_datastore_fetch[] = 'premium_members';
Then manually run the Hourly Cleanup scheduled task to store a value, then you can use {vb:raw vbulletin->premium_members} in whatever template you want.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.