6

I tried implemented a code in my Navigation/left.phtml

The code is as follows

    <!-- subcategory code -->

    <?php

    $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
    if(!$category->getChildren()){
     //$parentcat_id = $category->getParentCategory()->getId();
     //$category = Mage::getSingleton('catalog/category')->load($parentcat_id);
     $category = $category->getParentCategory();
    }
    $categories = $category->getCollection()
            ->addAttributeToSelect(array('name', 'thumbnail'))
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren());
     ?>
     <div class="block">

     <div class="block-title">
        <span><?php echo $category->getName() ?></span>

        </div>
        <div class="block-content clearfix">
    <ul class="subcategories">
        <?php foreach ($categories as $category): ?>
            <li>
                <a href="<?php echo $category->getUrl() ?>"><!--<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />-->
                    <span><?php echo $category->getName() ?>
                   <?php $collection = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($category);

    echo "(".count($collection).")"; ?></span>
                    </a>
            </li>
        <?php endforeach; ?>
    </ul></div>
    </div>
    <!-- subcategory code -->

    <!-- List all categories and their second level subcategories -->
    <div class="block block-list block-categories">
        <div id="block-categories" class="block-title active">
            <strong><span>Categories </span></strong>
        </div>

    <div id="leftnav" class="block-content" style="display:block">
        <?php $helper = $this->helper('catalog/category') ?>
        <?php $categories = $this->getStoreCategories() ?>
        <?php if (count($categories) > 0): ?>
            <ul id="leftnav-tree" class="level0">
                <?php foreach($categories as $category): ?>
                    <li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">

                        <?php //if ($this->isCategoryActive($category)): ?>
                            <?php $subcategories = $category->getChildren() ?>
                            <?php if (count($subcategories) > 0): ?>
                                <ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
                                    <?php foreach($subcategories as $subcategory): ?>
                                        <li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
                                            <a href="<?php echo $helper->getCategoryUrl($subcategory) ?>"><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a>
                                             <?php $secondLevelSubcategories = $subcategory->getChildren() ?>
                                             <?php if (count($secondLevelSubcategories ) > 0): ?>
                                <ul id="leftnav-tree-<?php echo $subcategory->getId() ?>" class="level2">
                                    <?php foreach($secondLevelSubcategories as $secondLevelSubcategory ): ?>
                                        <li class="level2<?php if ($this->isCategoryActive($secondLevelSubcategory )): ?> active<?php endif; ?>">
                                            <a href="<?php echo $helper->getCategoryUrl($secondLevelSubcategory ) ?>"><?php echo $this->escapeHtml(trim($secondLevelSubcategory ->getName(), '- ')) ?></a>
                                        </li>
                                        <?php endforeach; ?>
                                </ul>
                                <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
                            <?php endif; ?>
                                    <?php endforeach; ?>
                                </ul>
                                <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
                            <?php endif; ?>
                        <?php //endif; ?>
                    </li>
                <?php endforeach; ?>
            </ul>
            <script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
        <?php endif; ?>
    </div>
    </div>

But when i set Include in Navigation Menu to No it also disappears from here.

Is there any way I can hide from top menu and show in my side menu? I want to show all categories in left navigation using above code and only few categories in the top navigation.

I had also tired using custom category attribute but cannot create an attribute value with yes or no option. the script to create that attribute

            <?php
            $installer = $this;
            $installer->startSetup();
            $installer->addAttribute('catalog_category', 'topnav', array(
                'group'         => 'General Information',
                'type'     => 'int',
                'label'    => 'Top navigation',
                'input'    => 'boolean',
                'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                'visible'           => true,
                'required'          => false,
                'user_defined'      => false,   
                'default' => '',
                'option' => 
              array (
                'values' => 
                array (
                  0 => 'Please select',
                  1 => 'Yes',
                  2 => 'No',
                ),
              ),
                'source' => 'eav/entity_attribute_source_boolean'
            )); 
            $installer->endSetup();
            ?> 

And then calling

  if (!$category->getTopnav()) {
         continue;
         }

In observer.php

1

You can achieve this with the help of static blocks.By fetching all the categories into static block and displaying them in left navigation. For getting categories into a static block follow the procedure described here.After completing that process call your static block with <reference name="left"> and later for hiding categories from top nav goto app/design/frontend/your_theme/default/template/page/html and open topmenu.phtml file and put this code in comments

<?php if($_menu): ?>
    <nav id="nav">
        <ol class="nav-primary">
            <?php echo $_menu ?>
        </ol>
    </nav>
<?php endif ?>
| improve this answer | |
  • Thanks for the code. But I want to display selected categories on top navigation which can be done by setting Include in Navigation Menu to no . But as soon as I do that it also removes sub category from left nav – Bhargav Mehta Jan 2 '15 at 9:18
0

I solved this issue by removing the renderer for second child in my phtml file of header. Now my renderer.phtml looks like this:-

                <?php
                /**
                 * Magento
                 *
                 * NOTICE OF LICENSE
                 *
                 * This source file is subject to the Academic Free License (AFL 3.0)
                 * that is bundled with this package in the file LICENSE_AFL.txt.
                 * It is also available through the world-wide-web at this URL:
                 * http://opensource.org/licenses/afl-3.0.php
                 * If you did not receive a copy of the license and are unable to
                 * obtain it through the world-wide-web, please send an email
                 * to license@magentocommerce.com so we can send you a copy immediately.
                 *
                 * DISCLAIMER
                 *
                 * Do not edit or add to this file if you wish to upgrade Magento to newer
                 * versions in the future. If you wish to customize Magento for your
                 * needs please refer to http://www.magentocommerce.com for more information.
                 *
                 * @category    design
                 * @package     rwd_default
                 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
                 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
                 */

                /** @var Mage_Page_Block_Html_Topmenu_Renderer $this */
                /** @var Varien_Data_Tree_Node $menuTree */
                /** @var string $childrenWrapClass */

                $html = '';

                $children = $menuTree->getChildren();
                $parentLevel = $menuTree->getLevel();
                $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

                $counter = 1;
                $childrenCount = $children->count();

                $parentPositionClass = $menuTree->getPositionClass();
                $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

                foreach ($children as $child) {
                    $child->setLevel($childLevel);
                    $child->setIsFirst($counter == 1);
                    $child->setIsLast($counter == $childrenCount);
                    $child->setPositionClass($itemPositionClassPrefix . $counter);
                    if ($childLevel==1) {
                        $outermostClassCode = 'level'. $childLevel;
                    $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

                    $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';
                    $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '.'">'.'<img src="'.$this->escapeHtml($this->__($child->getThumbnail())).'" alt=""/>'. $this->escapeHtml($this->__($child->getName())).'</a>';

                    if (!empty($childrenWrapClass)) {
                        $html .= '<div class="'.'">';
                    }

                    $nextChildLevel = $childLevel + 1;

                             if (!empty($_hasChildren)) {
                        $html .= '<ul class="level'. $childLevel .'">';
                        $html .=     $this->render($child, $childrenWrapClass);
                        $html .= '</ul>';
                    }    



                    if (!empty($childrenWrapClass)) {
                        $html .= '</div>';
                    }

                    $html .= '</li>';


                    }

                    elseif ($childLevel!=2) {
                        $outermostClassCode = 'level'. $childLevel;
                    $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

                    $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';
                    $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'.'<img src="'.$this->escapeHtml($this->__($child->getThumbnail())).'" alt=""/>'. $this->escapeHtml($this->__($child->getName())).'</a>';

                    if (!empty($childrenWrapClass)) {
                        $html .= '<div class="'. $childrenWrapClass .'">';
                    }

                    $nextChildLevel = $childLevel + 1;

                             if (!empty($_hasChildren)) {
                        $html .= '<ul class="level'. $childLevel .'">';
                        $html .=     $this->render($child, $childrenWrapClass);
                        $html .= '</ul>';
                    }    



                    if (!empty($childrenWrapClass)) {
                        $html .= '</div>';
                    }

                    $html .= '</li>';


                    }


                    $counter++;    
                }

                return $html;

Hope this helps to someone.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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