Jump to content

Display number of members in a group


Mcardle

Recommended Posts

Posted

Hello,

I would like to display on the front end the amount of members in a group that will update automatically. Basically we run a game server where access is purchased through our store and once we have X amount of members with access we upgrade it, we would like to show members how many people have access via the group so they can see how close we are to the next upgrade if that makes sense.

So like what you see in the ACP > Members > Groups but being able to put it in PHP or a block on the front end.

Thanks :) 

Posted
24 minutes ago, MadMcardle said:

Thanks for the reply @Daniel F would I copy that in to a block? I'm not as experienced as my profile may imply :p 

Exactly.
 

$group = \IPS\Member\Group::load(4);
$count = $group->getCount();

echo "Total members in group 4:" . $count;

 

Posted
2 hours ago, MadMcardle said:

Sorry Daniel, how do I find out the number of the group? And I would simply change the 4 to that number? At the moment it is just showing the code front end :unsure:

 

Yes, change the 4 to the group id ( which can be found in the URL while editing the group)

You'll need to create a php block as described here:

Posted

Geez this was so simple actually, I was just over thinking it and making it complicated lol, need to learn php a lot more, thanks for the help :) 

  • 4 weeks later...
Posted
6 hours ago, Zephers said:

Thanks for this - if I wanted multiple groups in the same block with their counts (like a list) how would you code that?

Create html block

<ul>
	{{foreach \IPS\Member\Group::groups(true, false) as $group}}
		<li>
			{$group->formattedName|raw}: {$group->getCount()}
		</li>
	{{endforeach}}
</ul>

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...