| Show Different Content to Different Joomla Users |
| Thursday, 22 July 2010 09:47 |
|
Yesterday I showed how to Hide Columns When Editing the Front End of Joomla as it often causes overlap issues that make editing difficult. In this post I'll show a quick and easy way to show different content to different users. Being able to show different content to registered and logged in visitors is a very common request for a Joomla site. By default, you can have Joomla show the "intro" copy to guests and they must to log in to see the rest. But what if you want to show some specific content to guest visitors, and then different content to registered users once they have logged in. There are a couple of extensions that give this functionality, but as a rule of thumb, I'll always trying and use the core if I can to get what I want. In this case, I figured out a simple method that worked for my needs. First we need to make available information (aka accessing the user object) about the user, such as their name, or in this case, their user level. To do this, we insert the following in the head of our template: $user =& JFactory::getUser(); We can now echo all sorts of information about the user in the template, for example: <p>Hi <?php echo $user->name ?>, you haven't logged in since Remember, this has to be in the template index.php, you can't echo this in an article or module as it needs to be processed at the template level. Showing Different Content to Different UsersSo now we use some CSS... In our head we put: <?php Now, anything I want only guests to see, I surround with a class of logguest, anything I want only a logged in user to see I put a class of logmember. More importantly, because its now CSS, I can put it in a module or article! For example: <p class="logguest"> One thing to bear in mind, the content is still there, but its just not being shown via CSS, so Google will still see it (for example). Its a crude, but simple technique. Other Content Hiding OptionsIf you need more control over what content is shown to what users, check out David Towers excellent review of JoomiHide, Ninja Access - JACL and RokAccess Other User Object VariablesThe full list can be found on the Joomla wiki:
This article has an SEO score of 100% and content, joomla, users, and show are emphasized within the content and are considered Primary Keywords. |
Want a Joomla website, but don't have an IT department?
Simplweb provides fully managed Joomla hosting on high performance cloud servers. Unlimited support on Joomla, managed backups, security and updates.
Find out more how Simplweb can make Joomla... "Simpl" and start building a successful Joomla webiste with our free month trial. We'll send you some more information and you'll be first in line join the easiest and fastest way to learn Joomla.