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 ?
$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>';
}
}