Community Documentation

Insert Subscribed Organic Groups List

Last updated August 27, 2009. Created by wheatbix on May 5, 2007.
Edited by ronald_istos, add1sun. Log in to edit this page.

You can add a list of groups that the user has subscribed to with the following snippet. Keep in mind that if you use this snippet outside of the user profile template as set up on the Customising the user profile layout page you may need to add global $user; at the beginning to make sure you have the full user object to work with.

<h2>Groups</h2>
<div class="item-list"><ul>
<?php
$groups
= $user->og_groups;
if(
$groups){
    foreach(
$groups as $group){
    echo
"<li>";
        print
l($group[title], 'node/'.$group[nid]);
    echo
"</li>";
    }
}
else {
    echo
"<li>$user->name has joined no groups</li>";
}
?>

</ul>

Comments

with permissions check

If you only want to list the groups the current user has rights to visit:

<?php $profile = $user;
global
$user;
if(
$groups = $profile->og_groups) : ?>

<h3>Memberships</h3>
<div class="item-list"><ul>
<?php
   
foreach($groups as $group){
   
$tmp_node = node_load($group['nid']);
    if(
node_access('view', $tmp_node))
      print
'<li>' . l($group[title], 'node/'.$group[nid]) . '</li>';
    unset(
$tmp_node);
    }
?>

</ul>
</div>
<?php endif; ?>

Hi, I want to do a similar

Hi,

I want to do a similar thing but I don't know how. I want to display the list of the subscribed groups of the user actually visited.

Example : I visit the page of user USER123 and I want the list of the groups USER123 have subscribed.

Any idea ? Wich variable I have to use ? ($user is for the user actually connected)

Thanks

Is it possible to create a

Is it possible to create a list of all the groups in the registration form ??
and when the user validate his inscription and the groups, his account is creat and he joint the group... ??

thanks

About this page

Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here