Category Navigation Listings in Magento

0 votes
547 views
asked Jun 29, 2016 in Magento by Jennifer Diaz
I wish I could solve this myself, but its a high-end gamble for me now to make this work and finish it off before this weekend along with other tasks on the project. If possible somebody can help me with the code for the following requirement please?

How can we manually make category navigation listings in Magento?

1 Answer

0 votes
answered Jul 8, 2016 by Ajil Raj
Make sure the block that you’re working is of the type catalog/navigation. If you’re editing catalog/navigation/left.phtml then you should be okay.

<div id="leftnav">
    <?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; ?>">
                    <a href="<?php echo $helper->getCategoryUrl($category) ?>"><span><?php echo $this->escapeHtml($category->getName()) ?></span></a>
                    <?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>
                                    </li>
                                <?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>

Related questions

0 votes
1 answer 446 views
asked Jun 29, 2016 in Magento by Akshay Raj
0 votes
1 answer 384 views
0 votes
1 answer 347 views
asked Jun 13, 2016 in Magento by Don
+1 vote
1 answer 589 views
0 votes
2 answers 394 views
0 votes
1 answer 247 views
...