With the help of Joomla conditional statements you will able to show/hide different sections or say different parts of your website based on specific conditions. And I hope after reading this post you are going to avoid preparing different Joomla templates for different pages, as the below code snippets will help you out in cut short your work load.
Homepage detection code for Joomla 1.5
<?php if (JRequest::getVar('view')=='frontpage') { ?>
// your code or sections goes here that shows only on frontpage
<?php } ?>
In some of the Joomla 1.5 native versions, above code won’t works so as an alternative you can go with the below code
$menu = &JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
// your code or sections goes here that shows only on frontpage
echo 'This is the front page';
} ?>
Homepage Detection Code for Joomla 1.7 and Joomla 1.6
So there is no difference between the Joomla 1.5 and Joomla 1.7 code beside a character “&” in the first line so “&JSite” is for Joomla 1.5 and “JSite” is for Joomla 1.7 and 1.6
<?php
$menu = JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
// Script here will execute only on frontpage.
echo 'This is the front page';
}
?>
Homepage Detection Code for Multilingual Site – Works on Jooml 1.6 and Joomla 1.7
On Multilingual sites front page depends on the currently selected language, so we need to use this code –
<?php
$menu = JSite::getMenu();
if ($menu->getActive() == $menu->getDefault( 'en-GB' )) {
// Script here will execute only on English version frontpage.
echo 'This is the front page of English version';
}
elseif ($menu->getActive() == $menu->getDefault( 'fr-FR' )) {
// Script here will execute only on French version frontpage.
echo ' This is the front page of French version';
}
?>
Joomla ItemID Detection Code
With the help of below code you will able to detect the site page based on itemID. So you just need to replace ‘ItemID’ in the below code with the actual ItemID
<?php if (JRequest::getInt('Itemid') == your_id) : ?>
// You are currently on page whose ItemID is "XX”
// Place your content here
<?php endif; ?>
Joomla Menu Alias Detection Code
With the help of below code you will able to detect the site page based on its Menu Alias
<?php $theMenu = JSite::getMenu();
$theActiveMenu = $theMenu->getActive();
if ( strpos($theActiveMenu->alias, 'your-menu') !== false ) {
// You are currently on page whose menu alias is "your-menu”
// Place your content here
} ?>






