Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
systems:joomla:joomla_1.5_template_tutorial [2009/01/28 08:56]
127.0.0.1 external edit
systems:joomla:joomla_1.5_template_tutorial [2012/07/12 21:19] (current)
smayr
Line 561: Line 561:
  
  
-===Source===+===References===
  * Graf, Hagen. '''Chapter 13: Writing Your Own Joomla! Templates''', [[http://www.packtpub.com/joomla-version-1-5/book|Building Websites with Joomla! 1.5]],  Packt Publishing, 2008.  * Graf, Hagen. '''Chapter 13: Writing Your Own Joomla! Templates''', [[http://www.packtpub.com/joomla-version-1-5/book|Building Websites with Joomla! 1.5]],  Packt Publishing, 2008.
  * Sejal, [[http://www.themeswiki.org/Creating_Joomla_1.5_Templates|Creating Joomla 1.5 Templates]].  * Sejal, [[http://www.themeswiki.org/Creating_Joomla_1.5_Templates|Creating Joomla 1.5 Templates]].
 +
 +== Guest-Only Modules ==
 +=== Hide modules from registered users in Joomla 1.5 ===
 +
 +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:<code><position>guestsonly</position></code>
 + # 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: <code php>
 +<?php
 +$user =& JFactory::getUser();
 +if($user->guest){
 +?>
 +
 +<jdoc:include type="modules" name="guestsonly" style="xhtml" />
 + 
 +<?php
 +}
 +?>
 +</code>
 +  # Save and close the file.
 +
 +==== 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!
 +
 +=== References ===
 +  * [[http://www.aleixcortadellas.com/main/2009/08/09/hiding-modules-from-registered-users-in-joomla-1-5/|Hiding Modules from Registered Users in 
 +Joomla 1.5]]
 +
 +=== Joomla 1.7 - 2.5 ===
 +
 +==== Create a New User Group in User Manager ====
 +  * Create user group ''Guest'' (parent ''Public'').
 +
 +==== Create a New Access Group in User Manager ====
 +   * Create ACL ''Guest''.
 +   * Select group ''Guest''.
 +
 +==== Edit the Public Access Group in User Manager ====
 +   * Edit ACL ''Public''.
 +   * Select group ''Public'' and ''Guest''.
 +
 +==== Change Access Levels in Articles, Menus, and Modules in Module Manager ====
 +   * Select Access = ''Guest'' for those articles or modules that need viewing only by guest users (not Registered).
 +
 +=== References ===
 +   * [[http://www.cmsmind.com/joomla-1-7-5-easy-steps-to-create-guest-only-access-to-menus-and-modules|Joomla 1.7.5 easy steps to create guest-only access to menus and modules]]
 +