|
Hello,
I was looking for something like this but I didn’t really find what I searched. So I try to do something with my knowledges, I want to post this solution for others.
Why do I need a different header for the homepage? It was because I followed the SEO tutotial of Yoast which says that it is good to have on the home page a H1 for the logo and change the H1 tag for other content more important like category title for the other pages. So to be able to do that, the header of the homepage has to be different from the other.
My homepage uses the “2column right” (and some other pages too), but in all my theme I never use the “2column left bar”. So first you need to copy the content of “2column right” in “2column left” (file in app/design/frontend/default/theme/template/). In fact your homepage will use the “2column left” file (which is now a 2column right as we have paste the content)
Now we have to copy the content of app/design/frontend/default/theme/template/html/header.phtml into the right place in our 2column-left.phtml like this (between the header comment):
<div class="wrapper"> <?php echo $this->getChildHtml('global_notices') ?> <!-- start header --> <div class="header"> <div class="header-top-container"> <div class="header-top"> <?php $theader = Mage::getModel('Mage_Page_Block_Html_Header'); ?> <h1 id="logo"><a href="<?php echo $theader->getUrl('') ?>"><img src="<?php echo $theader->getLogoSrc() ?>" alt="<?php echo $theader->getLogoAlt() ?>" /></a></h1> <h5 class="slogan"><?php echo $this->__('www.website.com') ?></h5> <p class="no-display"><a href="#main"><strong><?php echo $this->__('Skip to Main Content') ?> »</strong></a></p> <?php echo $this->getChildChildHtml('header', 'topSearch') ?> <div class="quick-access"> <p class="welcome-message"><?php echo $theader->getWelcome() ?></p> <div class="shop-access"> <?php echo $this->getChildChildHtml('header', 'topLinks') ?> </div> </div> <?php echo $this->getChildChildHtml('header', 'store_language') ?> <?php echo $this->getChildChildHtml('header', 'headerCart') ?> </div> </div> <?php echo $this->getChildChildHtml('header', 'topMenu') ?> </div> <!-- end header -->
If you only do this it wont work because the getChildHtml is in the wrong place and the header model doesnt exist.
So we need to include the model of the Header.phtml with this line:
<?php $theader = Mage::getModel('Mage_Page_Block_Html_Header'); ?>
We need to replace $this by $theader for getUrl, getLogoSrc, getLogoAlt and getWelcome.
You also have to change the getChildHtml to getChildChildHtml(’header’,’...’) because to get the block you have to go through the block header first.
And it is done, this 2column-left.phtml will be our homepage (select this template in the administration>CMS Page for the homepage) you can change whatever you want whithout modifying the header of the non homepage page… If you wish to modify the header of the others pages just edit app/design/frontend/default/theme/template/html/header.phtml
I am not a Magento professional, so if you find some improvements that I can do, you are welcome!!!
|