Joomla Conditional Statements

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

Related posts:

Author:

is co-founder and author of tips4developer. By profession he is a WordPress and Joomla developer.


Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin

Joomla – Allowing

Recently I got an requirement to add multiple email ID’s ...

WordPress - Controll

Page Lists Plus is one of the most use full ...

IE compatible mode

I noticed most of the web developers and designers hate ...

Adding PayPal Donate

Adding PayPal Donate Button in WordPress Post and Page are ...

Multi Browsers CSS H

Here I am sharing few of the very useful multi ...

Joomla – Allowing

Recently I got an requirement to add multiple email ID’s ...

Virtuemart – Setti

In my last project I got a requirement from my ...

3 Best Security Ext

Joomla is one of the fastest growing and best CMS ...

Joomla Conditional S

With the help of Joomla conditional statements you will able ...

Virtuemart - Special

Here I am sharing the virtuemart code snippet to display ...