Insert Subscribed Organic Groups List

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>

with permissions check

gcassie - June 3, 2008 - 15:06

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; ?>

 
 

Drupal is a registered trademark of Dries Buytaert.