2

I would like execute a css style but only for a specific Joomla user group. My goal was to include the php code directly inside my Joomla template.

I try to found how to do (I'm not a coder) and I make some test but without success. For example I found this code in a forum:

<?php
$user =& JFactory::getUser();
if (!$user->author) {
?>
<style>#myclass{display:none; width:0px;}</style>
<?php
}
?>

But this don't work because I want execute the style by Usergroup ID and also because this code seem to be for Joomla 1.5 and I'm under Joomla 2.5.

Any clue please ?

Techie
  • 44,706
  • 42
  • 157
  • 243
dotcom22
  • 249
  • 1
  • 7
  • 19

1 Answers1

2
$user =& JFactory::getUser();
$groupIDs = array();
foreach( $user->groups as $groupID ){
  $groupIDs[] = $groupID;
}

var_dump( $groupIDs );

If you $groupIDs array contains the ids you need echo the styles as you have done now. Remember $groupIDs is an array, so you will have loop through the array to find the ids you need. Use a foreach to get it done.

If you have any issues let me know.

Updated answer as requested.

$user =& JFactory::getUser();
$groupIDs = array();
foreach( $user->groups as $groupID ){
  $groupIDs[] = $groupID;
}
foreach($groupIDs as $groupID)
{
 if($groupID == 2)
 {
 echo '<style>#myclass{display:none; width:0px;}</style>';
 }
}
Techie
  • 44,706
  • 42
  • 157
  • 243
  • Thank for answer but can you write down the exact code (ready to paste in my template file) including the CSS and the group ID number who in my case is number 2 please? Like I say I'm not a coder and I don't have any good knowledge. I tried many time to learn a bit but is just a nightmare :-(. Thanks – dotcom22 Dec 30 '12 at 09:24
  • which group no do you want to have the styles? – Techie Dec 30 '12 at 10:22
  • the group number 2 who is Registered. But in future I can maybe need to disallow some other style for some other custom group..reason why I think is best to specify the group ID. thank – dotcom22 Dec 30 '12 at 10:48