0

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.

1
  • In admin open you sub-category. go to Display settings. select Is Anchor to "Yes" May 3, 2017 at 10:06

1 Answer 1

0

(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 '&emsp;' . '<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 '&emsp;&emsp;' . '<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

7
  • is this possible to achieve without using module? May 3, 2017 at 12:23
  • You can skip module for layout. and instead of that you can assign diffrent layout to parent category(1column) and sub-category(2columns-left) from catalog>manage categories>Custom Design>Page Layout.
    – Lalit838
    May 3, 2017 at 13:37
  • there is any other method available? May 3, 2017 at 13:38
  • in your answer i can't find app/design/frontend/yourtheme/yourtemplate/layout/page.xml this file May 3, 2017 at 13:39
  • Please create path if it not exist <yourtheme> and <yourtemplate> defines the theme and layout you are using in your magento 1.9
    – Lalit838
    May 3, 2017 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.