Magento : Check if Current Page is Homepage?

There are two ways to check check if Current Page as Homepage in Magento.

1) Global way to get check either in class file or template file :

<?php

if(Mage::getBlockSingleton(‘page/html_header’)->getIsHomePage()) {
    echo ‘It is a Homepage!’;
} else {
    echo ‘It is NOT a Homepage!’;
}

?>

OR

<?php

$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton(‘cms/page’)->getIdentifier();

if($routeName == ‘cms’ && $identifier == ‘home’) {
    echo ‘It is a Homepage!’;
} else {
    echo ‘It is NOT a Homepage!’;
}

?>

2) If you are in template/page/html/header.phtml template file, following code snippet is useful to check for homepage:

<?php

if($this->getIsHomePage()) {
    echo ‘It is a Homepage!’;
} else {
    echo ‘It is NOT a Homepage!’;
}

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s