Actions

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

From Joomla! Documentation

m (Added category)
m (Ading 1.6 conditional statement version)
Line 1: Line 1:
 +
== Joomla 1.0 ==
 +
 
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 lang="php">
Line 7: Line 9:
 
?>
 
?>
 
</source>
 
</source>
 +
 +
== Joomla 1.5 ==
 +
 
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 lang="php">
Line 17: Line 22:
 
</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.
 +
 +
== Joomla 1.6 ==
 +
 +
For the 1.6 version, the conditional statement, became even shorter. This is the result for Joomla! 1.6.x
 +
<source lang="php">
 +
<?php
 +
if(JRequest::getVar(‘view’) == “frontpage” ) :
 +
    echo 'This is the front page';
 +
else :
 +
    echo 'This is the other pages';
 +
endif;
 +
?>
 +
</source>
 +
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.
 +
<source lang="php">
 +
<?php
 +
$menu = &JSite::getMenu();
 +
if (JRequest::getInt(‘Itemid’) == $menu->getDefault()) : ?>
 +
    echo 'This is the front page';
 +
else :
 +
    echo 'This is the other pages';
 +
endif;
 +
?>
 +
</source>
 
<noinclude>
 
<noinclude>
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
</noinclude>
 
</noinclude>

Revision as of 20:34, 14 March 2011

Joomla 1.0

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

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

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’) == “frontpage” ) : 
    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; 
?>