I'm new in magento 1.9
I need to showing categories in sub category page under layered
navigation. I searched in internet but I can't find exact solution.
Can anyone pls help me.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI'm new in magento 1.9
I need to showing categories in sub category page under layered
navigation. I searched in internet but I can't find exact solution.
Can anyone pls help me.
(You can choose 1column Layout and 2columns-left layout for parent and sub categories)
OR As per your needs you have to define a new layout to parent category and sub categories, to do so you have to create a module to show layout option on catalog category page on magento admin panel,
First add this code to your Local Instance of code files.
app/code/local/Codemazes/CategoryLayout/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Codemazes_CategoryLayout>
<version>0.0.1</version>
</Codemazes_CategoryLayout>
</modules>
<global>
<page>
<layouts>
<subcategory module="page" translate="label">
<label>Category Layout</label>
<template>page/category.phtml</template>
<layout_handle>lookbook</layout_handle>
</subcategory>
<parentcategory module="page" translate="label">
<label>Parent Category Layout</label>
<template>page/parent-category.phtml</template>
<layout_handle>lookbook</layout_handle>
</parentcategory>
</layouts>
</page>
</global>
</config>
And add Module file in app/etc/modules/
<?xml version="1.0"?>
<config>
<modules>
<Codemazes_CategoryLayout>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</Codemazes_CategoryLayout>
</modules>
</config>
Add two .phtml
file in app/design/frontend/yourtheme/yourlayout/template/page
named as category.phtml
and parent-category.phtml
.
For some convenience i would prefer to use 2columns-left.phtml
layout in category.phtml
file(copy the code), And 1column.phtml
file layout to parent-category.phtml
On category.phtml add this code just before .col-main class
<aside class="col-left sidebar">
<?php echo $this->getChildHtml('left'); ?>
</aside>
Now You should have an option In Catalog>Manage Categories>Custom Design>Page Layout choose 'category layout' for Sub-categories and 'Parent Category' layout for parent categories.
Now we have to add Navigation to our custom layout's left sidebar.
edit
Open app/design/frontend/yourtheme/yourtemplate/layout/catalog.xml
. Place the following code under <catalog_category_default translate="label">
:
edit
<reference name="left">
<block type="core/template" name="catalog.sidenav" template="page/html/cat-navigation.phtml" before="_"/>
</reference>
Create app/design/frontend/yourtheme/yourtemplate/template/page/html/cat-navigation.phtml
with the following content:
<ul>
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li>
<strong><?php echo $_category->getName(); ?></strong>
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<ul>
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>';
?>
</li>
<?php if($categoryGrandchildren->count()) : ?>
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
</ul>
This will get you 3-levels of categories on your left side bar, All you need to do is add this block to your left sidebar through:
<?php echo $this->getChildHtml('catalog.sidenav') ?>
Hope this helps