We have already discussed how to hide template elements from logged in members in this tutorial, but what about if we wish to only display template elements on certain pages.

Taking the same example used in the previous tutorial, we can easily modify the code so that it is displayed only on the home page.

Here is the code we used to hide template elements from logged in users

<?php 
$user = JFactory::getUser();
if($user->guest ) : ?>
...
...
<?php endif; ?>

We can expand this simple method to only display the template elements on specific pages. This is done by checking the item ID for the page like this...

<?php 
$user = JFactory::getUser();
if($user->guest && JRequest::getInt('Itemid') == 101)) : ?>
...
...
<?php endif; ?>

To find the item ID for the page, simply check the value for the ID column in the article manager, and substitute this in the statement above.