How to determine if the user is viewing the front page
From Joomla! Documentation
Revision as of 16:04, 1 April 2011 by Chris Davenport (talk | contribs) (Ampersand is superfluous as Joomla 1.6 requires PHP 5.)
Revision as of 16:04, 1 April 2011 by Chris Davenport (talk | contribs) (Ampersand is superfluous as Joomla 1.6 requires PHP 5.)
Joomla 1.0[edit]
In Joomla! 1.0.x it was possible to determine if the user was viewing the front page by using code like this:
<?php
if ($option == 'com_frontpage' || $option == '') {
echo 'This is the front page';
}
?>
Joomla 1.5[edit]
But in Joomla! 1.5.x the com_frontpage component is no longer present. This is how to achieve the same result in Joomla! 1.5.x
<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
}
?>
This works by checking to see if the current active menu item is the default one.
Joomla 1.6[edit]
For the 1.6 version, the conditional statement, became even shorter. This is the result for Joomla! 1.6.x
<?php
if(JRequest::getVar(‘view’) == “featured” ) :
echo 'This is the front page';
else :
echo 'This is the other pages';
endif;
?>
You can also use the default menu option to check the home page. If the menu is activated, the default item for menu would be home page.
<?php
$menu = JSite::getMenu();
if (JRequest::getInt(‘Itemid’) == $menu->getDefault()) : ?>
echo 'This is the front page';
else :
echo 'This is the other pages';
endif;
?>