I have about 6 different groups, eg Team A, Team B etc. I would like to display a block for one of these groups. Was thinking something like checking if the logged in users gid = X then display the block. That way I can setup 6 different blocks all targeting the different groups so that when the user is logged in, it will display the relevant block for them. Does that make sense? How would I implement it?
Depending on your exact setup, it looks like the Context module may help you.
Here's how you can do that.
Creating a new context allows you to show certain blocks for only CERTAIN CONTEXTS. Example contexts are showing blocks on only certain pages (via the Path context) or only for users of a certain role (via the User role context) or even on certain node types or on pages that have a certain term attached, etc.
In your case, if you are using the Organic Groups module to implement your user groups, context will integrate with that. That means that when you create your context, there will be an option under the 'Conditions' section to select the Organic Group you want to show certain blocks for. You choose the exact blocks you want to show in the 'Reaction' section.
Let us know if that helps!
After more than a week of research and playing around, I found a little bit of code and modified it below to what I needed.
<?php
global $user;
$uid = $user->uid;
$result = db_query ( "SELECT * FROM {og_membership}
WHERE etid = :uid
and entity_type = 'user'
order by gid DESC", array (':uid' => $uid ) );
foreach ( $result as $row ) {
$gid = $row->gid;
break;
}
?>
<?php if ($gid == "GROUP ID HERE"): ?>
(load block here)
<?php endif; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With