edit the file /app/design/frontend/{package}/{theme}/template/catalog/layer/view.phtml
and replace this line:
<?php if($_filter->getItemsCount()): ?>
with
<?php if($_filter->getItemsCount() > 1): ?>
I only see one problem with this approach.
If all your filters have only one option they you will still get the section title
<p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
But this can easily be overcome if you loop through the available filters and see if you have at least one that has the items count bigger than 1.
This is what I understood from your question. You want to remove category filter for your two top categories (for them, isAnchor
is set to Yes
) and keep all other filters as it is.
To achieve this, most easiest solution is a category specific layout update via any of your layout update xml file. For example, your category id be 12
. Then add below code in your local.xml
file.
File : app\design\frontend\[package]\[theme]\layout\local.xml
<layout>
<CATEGORY_12>
<reference name="catalog.leftnav">
<action method="unsetChild"><alias>category_filter</alias></action>
</reference>
</CATEGORY_12>
</layout>
Here CATEGORY_12
is a layout handle update which is specifically created for a category with an id 12. Inside that, we are basically removing category filter from layered navigation.
Hope you get the idea.
EDIT
So you want to remove category filter and keep all other filters intact. To do that, I believe you need to rewrite the class Mage_Catalog_Block_Layer_View
which you can find at app/code/core/Mage/Catalog/Block/Layer/View.php
protected function _prepareLayout()
{
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
->setLayer($this->getLayer());
$categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
->setLayer($this->getLayer())
->init();
$this->setChild('layer_state', $stateBlock);
$this->setChild('category_filter', $categoryBlock);
//CATEGORY IDS IN WHICH YOU WANT TO HIDE OTHER FILTERS
$excludeCategories = array(12, 13); //example
$currentCategory = Mage::registry('current_category');
//avoid rendering attribute filters for exclude categories
if (!in_array($currentCategory->getId(), $excludeCategories)) {
$filterableAttributes = $this->_getFilterableAttributes();
foreach ($filterableAttributes as $attribute) {
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = $this->_priceFilterBlockName;
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = $this->_decimalFilterBlockName;
} else {
$filterBlockName = $this->_attributeFilterBlockName;
}
$this->setChild($attribute->getAttributeCode() . '_filter',
$this->getLayout()->createBlock($filterBlockName)
->setLayer($this->getLayer())
->setAttributeModel($attribute)
->init());
}
}
$this->getLayer()->apply();
return parent::_prepareLayout();
}
Use your category ids in $excludeCategories
and you are good to go.
Best Answer
Hi if you want to delete you layered navigatino category wis then you can use below: Admin Menu: catalog->cateogry