How to show a list of registered users in Joomla?

2019-09-02 02:29发布

问题:

I have hundreds of registered users. Those are grouped in different user groups:

See screenshot below (I changed this a little bit to protect my customers site):

  • Registered -> Teachers
  • Registered -> Students

How can I show a list of 'Teachers' online? I want to list up all those teachers in a table or list, so that other teachers see this information.

Thank you. Any information is welcome.

回答1:

You can use the following for to get the usernames from a specific user group:

$teachers = JAccess::getUsersByGroup(2); //change number in the brackets
$students = JAccess::getUsersByGroup(8); //change number in the brackets
foreach($teachers as $user_id) {
    $user = JFactory::getUser($user_id);
    echo $user->name;
}
foreach($students as $user_id) {
    $user = JFactory::getUser($user_id);
    echo $user->name;
}

Change "2" and "8" to the ID's of the Teachers and Students user groups.

Hope this helps



回答2:

Personally, I think the best way to do that is to create a contact category teachers and then link each teacher to a contact record.

You can make a list of users in a group (there's even a method JAccess::getUsersByGroup() but I don't think it's that useful for this purpose. http://officialjoomlabook.com/school25/staff-directory is an example of where I did what I am suggesting.



标签: list joomla