Hiding My Groups block when there is nothing to show

Last modified: July 16, 2009 - 14:52

If a user is not a member of any groups, the My Groups block can still show.

To hide the block when the user is not a member of any groups, do the following:

1. Go to admin/build/block

2. Find the My Groups block. Click the Configure link.

3. Scroll down to "Page specific visibility settings." Check "Show if the following PHP code returns TRUE"

4. Paste this in the <textarea>:

<?php
global $user;
$uid= $user->uid;
$sql = "SELECT COUNT(*) FROM {og_uid} WHERE uid = %d";
$cnt = db_result(db_query($sql, $uid));
return
$cnt > 0;
?>

5. Click the "Save block" button.

 
 

Drupal is a registered trademark of Dries Buytaert.