-
Hide modules from registered users in Joomla 1.5
Posted on August 9th, 2009 2 comments
While Joomla 1.5 allows hiding modules from guests (and just show them to registered users), it lacks the ability to do the opposite, namely hiding modules from registered users. Of course such thing can be very useful when there are modules inviting users to register (how pointless to show them to already registered users!), or modules showing advertisements to guests.As said, the backend does not allow you to set a module to show to guests only, but this can be very easily done in a couple of minutes and minimal effort with a simple hack to the template code. NO need to install plugins or add-ons! It is a simple yet very useful trick.
After making a quick backup of the files which are to be modified, follow the steps:
1. Creating a new module position
What is shown or hidden to users, using this system, is not a single module but a position (and all the modules displayed in it). Examples of default Joomla 1.5 positions are banner, breadcrumb, left, footer, etc. and your Joomla might have further of them depending on the template you are using. We will now create a new position, where we will display the modules which we want to show to guests only; so we’ll call it guestsonly or any other name you like.
- Open the directory where the active template files are stored; it should be in your Joomla directory, in the templates folder.
- Open the file templateDetails.xml. In it you will find a number of lines preceded by the <position> prefix; These positions are shown in the dropdown menu of the backend; so while it is not necessary to perform the next step for the trick to work, it will allow you to easily include new modules to that position, directly from the backend.
- Add one more line with the name you chose for your new position, so it should look like:
<position>guestsonly</position>
- Save and close the file.
2. Placing the position and PHP code in the layout
- Now, in the same template directory, open the file index.php. This contains the layout of the template.
- Add the following lines (replacing the name of the position if appropriate) wherever you want that position to be in the layout:
- Save and close the file.
<?php $user =& JFactory::getUser(); if($user->guest){ ?> <jdoc:include type="modules" name="guestsonly" style="xhtml" /> <?php } ?>
3. Final steps
Once you’ve successfully completed the steps above, you already have your ‘guests only’ position! Now all you need to do is add new or place existing modules to it, editing the module settings from the backend and selecting the new position as theirs. Test if it works by logging in and out from the frontend (just in case).
Note: the access level of those modules, in their settings, should be kept to “Public”. Don’t worry; the code we applied overrides that setting and will only show it to unregistered users!
Computers & programming, Content Management Systems, HTML, PHP cms, guests, joomla, modules, php, registered, users2 responses to “Hide modules from registered users in Joomla 1.5”
-
Exactly what I needed for a member-only Web site. Now we display basic membership info and the login box, and after they log in, they see the fancy home page with all the news. Thanks!
-
What an excellent blog, I’ve added your feed to my RSS reader.
Leave a reply


