Actions

Difference between revisions of "How to determine if the user is viewing the front page"

From Joomla! Documentation

(Importing text file)
 
m (Fixed markup.)
Line 1: Line 1:
======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:
 
In Joomla! 1.0.x it was possible to determine if the user was viewing the front page by using code like this:
 
+
<source lang="php">
<source>
+
 
<?php
 
<?php
 
if ($option == 'com_frontpage' || $option == '') {
 
if ($option == 'com_frontpage' || $option == '') {
Line 10: Line 7:
 
?>
 
?>
 
</source>
 
</source>
 
 
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
 
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
 
+
<source lang="php">
<source>
+
 
<?php
 
<?php
 
$menu = & JSite::getMenu();
 
$menu = & JSite::getMenu();
Line 21: Line 16:
 
?>
 
?>
 
</source>
 
</source>
 
 
This works by checking to see if the current active menu item is the default one.
 
This works by checking to see if the current active menu item is the default one.
 +
<noinclude>[[Category:Development]]</noinclude>

Revision as of 18:45, 28 December 2008

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.