Community Documentation

Hiding My Groups block when there is nothing to show

Last updated July 16, 2009. Created by mathieso on July 16, 2009.
Log in to edit this page.

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.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Site administrators
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.