Actions

How to determine if the user is viewing the front page

From Joomla! Documentation

Revision as of 21:15, 6 May 2008 by Maintenance script

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
How to determine if the user is viewing the front page

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.