‘Is Home Page’ conditional or Check if you are on the Home page in Magento 1.4 & 1.5

Written by Adrian Hart

Topics: Magento, Web Design

Do you need to put some content on the Home page of your Magento site, but not on others? Here’s how:

Open the relevant .phtml template file which contains the code you want to show on the Home page. Then add the code below depending on which version of Magento you are using…

In Magento version 1.4.x you need to run a check to see if the current URL matches the Home page URL. This piece of code is called a conditional. Our conditional to check if we are on the Home page would look like this…

<?php if( $this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true)) ):?>
Your HTML here...
<?php endif; ?>

In version 1.5, the Magento developers were kind enough to include a new global function…

$this->getIsHomePage();

So if you use Magento 1.5.x or newer, can use this conditional in our .phtml file…

<?php if( $this->getIsHomePage() ):?>
Your HTML here...
<?php endif; ?>

Much neater!

3 Comments Comments For This Post I'd Love to Hear Yours!

  1. Tashman says:

    What is the path to the .phtml file in which to add this code?

  2. jeric realubit says:

    getIsHomePage();
    ?>

Leave a Comment Here's Your Chance to Be Heard!