I would like to know how to hide header and footer for specific category ID. For example, I have 5 categories: categories are cat1, cat2, cat3, cat4, cat5. I want to hide header and footer in every pages if the category id is equal to cat1. Is it possible to do so?
4 Answers
Simon has a good answer but you can also do this through the admin control panel in Magento using a custom layout update setting on the category editor:
- Log in to your admin console and visit Catalog > Manage Categories.
- Select the category you want to change in the left column.
- Click the "Custom Design" tab in the middle column.
- Set "Use Parent Category Settings" to "No"
- inside the "Custom Layout Update" box add the following:
<remove name="header" />
<remove name="footer" />
- Save the category's changes and go check your website.
This will affect the selected category and all it's child categories by default. If you later want to change another category, you can repeat these steps on that category. You can also re-edit this category and reverse these steps to change the design of that category back again.
disclaimer
I tested this on 1.7 and I have just assumed that the same functionality exists in whichever version you are using.
-
Hi, Dear Russ Wilde, According to your guidance, I am able to hide header and footer for specific category. But what I want is that for category id 1, there will be products under category id 1. If I click the products which are under category id 1, I would like to hide header and footer for product detail page. In product detail page, I will click Buy Now button. After Buy Now button is clicked, product add to card page will be shown. I would like to hide header and footer of product add to card page also. Is it possible to do so?– May18Commented Aug 18, 2014 at 14:31
-
This is another problem and you should post another question for it.– SimonCommented Aug 18, 2014 at 15:11
-
Yes it is possible but the solution will be much more complicated than this technique. Categories are not the right way to separate out products to do this. I would suggest that you create two store views with different designs to do it, rather than just relying on categories, then have one store view that has no header or footer in it's design for the required pages, and offer those products through that store. Like Simon says, however, this is a different problem and would need a complicated answer.– 0x00hCommented Aug 18, 2014 at 15:38
-
Thank you so much! I am going to raise the question "How to create two store views with different designs" Please kindly help me for the problem I am going to raise. Thanks a lot!– May18Commented Aug 18, 2014 at 15:50
-
In addition to Simon's answer.
You can create a custom layout handle so you won't duplicate the code for every category.
Something like this:
<category_remove_header_footer>
<remove name="header" />
<remove name="footer" />
</category_remove_header_footer>
Then just use this handle in all the other category handles
<CATEGORY_1>
<update handle="category_remove_header_footer" />
</CATEGORY_1>
<CATEGORY_2>
<update handle="category_remove_header_footer" />
</CATEGORY_2>
....
<CATEGORY_5>
<update handle="category_remove_header_footer" />
</CATEGORY_5>
Replace 1, 2..5 with the real category ids.
This could be useful if you later want to change something for all these categories. You can do it in one place for all of them.
An other cleaner approach would be to add a new attribute to the category entity called 'Hide header and footer' ( code hide_header_footer
). It should be a 'Yes/No' attribute.
Then create the layout handle category_remove_header_footer
as mentioned above and rewrite the method Mage_Catalog_CategoryController::viewAction
and below
$update->addHandle('CATEGORY_' . $category->getId());
add this:
if ($category->getHideHeaderFooter()) {
$update->addHandle('category_remove_header_footer');
}
This involves more code, but it seams cleaner and portable. You may later want other categories with no header or footer. With this approach you can set that from the backend, without coding anything else.
There are specific layout handles for each category with a specific ID. Mind that the ID is solely numeric. If the ID is 1
, then you can do something like this in your local.xml
:
<CATEGORY_1>
<remove name="header"/>
<remove name="footer"/>
</CATEGORY_1>
-
Hello Simon, as I am the beginner, I do not know where to put the above code. local.xml is the one located under app\etc\local.xml? If it is, could you please guide me to put your code under which tag in local.xml? Thanks a lot.– May18Commented Aug 18, 2014 at 8:06
-
1Sorry, but a little bit of research is also required on your site. en.lmgtfy.com/?q=magento+local+xml– SimonCommented Aug 18, 2014 at 8:09
-
Hello Simon, when I put the code that you provided above, it hides the header and footer including home page and other category pages also. It hides every pages. I only want to hide the pages that are related to specified category id. Is it possible to do so? Thank you so much!– May18Commented Aug 18, 2014 at 15:04
-
Then you probably use it in a wrong way :/ You have to put it directly inside the
<layout>
tag.– SimonCommented Aug 18, 2014 at 15:11 -
It only hides for specified category page. But does not hide for product details page, product add to cart page and check out page as well. Is there a way to hide those? Thank you so much!– May18Commented Aug 18, 2014 at 15:35
create on an event on catalog page render and remove the footer and header by observer
<events>
<controller_action_predispatch_catalog_category_view>
<observers>
<myredirect>
<class>check/observer</class>
<method>myremove</method>
</myredirect>
</observers>
</controller_action_predispatch_catalog_category_view>
</events>
and observer code is
public function myremove($observer)
{
try{
if(Mage::registry('current_category'))
$catId=Mage::registry('current_category')->getId();
$specialCategoriesId=array('cat1','cat2',cat3);
if (in_array($catId, $specialCategoriesId)) {
$blockName = 'footer'; // Add yours
$update = Mage::app()->getLayout()->getUpdate();
$removeInstruction = "<remove name=\"$blockName\"/>";
$update->addUpdate($removeInstruction);
}
}catch(Excpetion $e){
Mage::log(print_r($e->getMessage(),1),'null','mage32173.log');
}
return;
}
-
Hello, Dear Amit Bera, your code only effects to my home page. It does not effect to the specified category id. Do I need to update something in myremove function? Thank you so much.– May18Commented Aug 18, 2014 at 8:37
-
Naing .i have put a static id Mage::registry('current_category')->getId()=2,Mage::registry('current_category')->getId() give current category id you need to put there you logic– Amit Bera ♦Commented Aug 18, 2014 at 9:26