Style members sections using a unique CSS ID

How many times have you found yourself wishing that you could style your Joomla! site differently for members than for the public? Well, we just got hired on a project that made this feature mandatory, so we set out to create code that would allow us to style the CSS separately. This is how it’s done:

Insert this PHP code just below your body tag. This will add an ID called #members when someone is logged in.


<?php if ( $my->id ) { echo '<div id="members">'; } else { }; ?>

Then add this just above the end body tag in your template:


<?php if ( $my->id ) { echo '</div>'; } else { }; ?>

You may now use some creative CSS to style things differently for members! For example, if you have a white header for the public, you can change it to red when members log in by using the following CSS:


#members #header {background:#990000}

If it doesn’t change for some reason, try adding !important on the end of the color and it will override any cascading issues.

I hope you find this little piece of code useful for your Joomla! projects. I know it has given us a LOT more control over our Joomla! pages. Enjoy!

STAY UP TO DATE

Sign up today to stay informed with industry news & trends