Layered Navigation on Home Page or Any CMS Page Magento
Magento does not allow this to happen and there are many plugins out there that charge a fortune for something which is relatively easily to do. We are going show you how to get the layered navigation to any of your CMS pages and how to give it a cool and sexy accordion effect using jQuery. There are a lot of forums which have this type of post but none of them work as well as this nor do they have an accordion effect too.
The first step is to navigate yourself to your CMS pages in the backend and update the XML file for your home page. This can be done by going to:
CMS > Manage Pages > Homepage > Layout Update XML and in here please place the code below:
Second step is going navigate yourself through some code. Please go to /app/code/local/mage/catalog/model/layer.php and do not rewrite the original file, make a copy of it in the local folder.
Find this code:
public function getCurrentCategory()
{
$category = $this->getData(‘current_category’);
if (is_null($category)) {
if ($category = Mage::registry(‘current_category’)) {
$this->setData(‘current_category’, $category);
}
else {
$category = Mage::getModel(‘catalog/category’)->load($this->getCurrentStore()->getRootCategoryId());
$this->setData(‘current_category’, $category);
}
}
return $category;
}
Replace the above code with this code below:
public function getCurrentCategory()
{
$category = $this->getData(‘current_category’);
if (is_null($category)) {
if ($category = Mage::registry(‘current_category’)) {
$this->setData(‘current_category’, $category);
}
else {
$category = false;
$this->setData(‘current_category’, $category);
}
}
//added to make this work for front page:
if(is_null($category) || $category == false) {
$home_category = Mage::getModel(‘catalog/category’)->load(40); //number must correspond to ‘all products page’ category
$this->setData(‘current_category’, $home_category);
$category = $this->getData(‘current_category’);
//return $category;
}
//end addition
return $category;
}
This is the only part where you will need to edit the core files but like suggested please place the code in the local folder rather then hacking the core files.
Next step is to create a file called homeview.phtml in /template/catalog/layer/ with the following code:
canShowBlock()): ?>
canShowOptions()): ?>
__(‘Shopping Options’) ?>
-
getFilters() ?>
- Type
-
-
load($id);
- “;
echo ‘(‘.Mage::getModel(“catalog/category”)->load($id)->getProductCount().’)‘;
echo “
if($childCategory->getName() == “shop” || ($childCategory->getEntityId() == 10 || $childCategory->getEntityId() == 11 || $childCategory->getEntityId() == 12 || $childCategory->getEntityId() == 13 || $childCategory->getEntityId() == 14
|| $childCategory->getEntityId() == 16 || $childCategory->getEntityId() == 17 || $childCategory->getEntityId() == 18 || $childCategory->getEntityId() == 19) ):
else:
echo ““;
endif;
endforeach;
?> - “;
- getName() ?>
- getHtml()) ?>
getItemsCount()): ?>
__($_filter->getName() == “Category”)): ?>
load(9);
$all_child_categories = $category_model->getResource()->getAllChildren($_category);
?>
Replace the category ids etc to match yours. This navigation should push through all of your attributes and all of you categories as well. The rest is up to you how you style it, if you have any question please comment on my blog thanks.