How to create custom header in magento 1.9
-
21-01-2021 - |
Domanda
I want to create the custom header in Magento 1.9. I attached the screenshot of the header like this
I have tried the following code. I have created the static block and static block calling in the header.phtml file
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('custom_block_id')->toHtml() ?>
but this code is not working .please suggest me
I have added this original header not working. Menu and logo not displaying.
<!--- custom header---->
<reference name="header">
<block type="page/header" name="header">
<action method="setTemplate"><template>page/html/customheader.phtml</template></action>
</block>
</reference>
<!--- original header---->
<reference name="header">
<!-- Search box wrapper -->
<block type="page/html_header" name="search_wrapper" template="page/html/search_wrapper.phtml">
<action method="insert">
<block>top.search</block>
</action>
</block>
Soluzione
Add the code bellow in :
app/design/frontend/{yourpackage}/{yourtheme}/layout/local.xml
<reference name="header"> <block type="{block}/{type}" name="custom.header" template="page/html/custom-header.phtml" before="-"/> </reference>
Create your custom header in :
app/design/frontend/{yourpackage}/{yourtheme}/template/page/html/custom-header.phtml
Add
<?php echo $this->getChildHtml('custom.header'); ?>
inapp/design/frontend/{yourpackage}/{yourtheme}/template/page/html/header.phtml
Info : in
<block type="{block}/{type}"
if you haven't a custom block for your phtml, please put :<block type="core/template" ...
before="-"
to place it at the top of the header container.
Update:
For a Static block:
in local.xml
<reference name="header">
<block type="cms/block" name="custom.header">
<action method="setBlockId"><block_id>block-id-here</block_id></action>
</block>
</reference>
Then : app/design/frontend/{yourpackage}/{yourtheme}/template/page/html/header.phtml
Add this : <?php echo $this->getChildHtml('custom.header'); ?>
Altri suggerimenti
Try to add this code in your xml :
<reference name="header">
<block type="core/template" name="customheader" template="customheader.phtml"/>
</reference>
And write your custom code in customheader.phtml file.
It may be helpful for you.