Actions

How to determine if the user is viewing the front page

From Joomla! Documentation

Revision as of 17:46, 28 December 2008 by Chris Davenport (Talk | contribs)

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';
}
?>

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.