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…
[code]<?php if( $this->getUrl(”) == $this->getUrl(‘*/*/*’, array(‘_current’=>true, ‘_use_rewrite’=>true)) ):?>
Your HTML here…
<?php endif; ?>[/code]
In version 1.5, the Magento developers were kind enough to include a new global function…
[code]$this->getIsHomePage();[/code]
So if you use Magento 1.5.x or newer, can use this conditional in our .phtml file…
[code]<?php if( $this->getIsHomePage() ):?>
Your HTML here…
<?php endif; ?>[/code]
Much neater!
Written by Adrian Hart
Topics: Magento, Web Design