$this->getIsHomePage() - Fix for Store Views [duplicate]
Domanda
I am trying to use this code, found here, in the header.phtml file on my Magento 1.9.x website. For some reason, even on the home page at .com/ or .com/?SID= it is still applying H3 where it should be H1.
Does anyone know why this might be happening? Do I need other info on the page?
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h1>
<?php else: ?>
<h3 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h3>
<?php endif ?>
This code is also running to test against false positives - This code works but is only doing an echo on the code, not actually rendering it to provide the alt text:
<div id="are-we-home" style="display: none; ">
<?php if($routeName == 'cms' && $identifier == 'home') { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } ?>
</div>
Soluzione
It's a bug. I think you're getting bitten by the same issue this guy is: 'Is home page' condition with different store views in magento not working
Replace your homepage check with this:
<?php
$action = Mage::app()->getFrontController()->getAction()->getFullActionName();
if ($action == 'cms_index_index'):
?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h1>
<?php else: ?>
<h3 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h3>
<?php endif; ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange