1

I want to display all catalog names from all the levels and I am using the following code and it shows the category at level 1 and I want a nested menu to be displayed

the following is the code snippet

<select id="<?php echo $categorySearchHelper->getCategoryParamName() ?>" name="<?php echo $categorySearchHelper->getCategoryParamName() ?>">
    <option value=""><?php echo $this->__('All') ?></option>
    <?php foreach ($this->getSearchableCategories() as $mainCategory): ?>
        <option value="<?php echo $mainCategory->getEntityId()?>"><?php echo $mainCategory->getName() ?></option>
        <?php if ($categorySearchHelper->showSubCategories()) : ?>
            <?php foreach ($this->getSearchableSubCategories($mainCategory) as $category) : ?>
                <option value="<?php echo $category->getEntityId()?>"><?php echo $categorySearchHelper->getIndentationText() . $category->getName()?></option>
            <?php endforeach;?>
        <?php endif ?>
    <?php endforeach;?>
</select>

Please help

1
<?php $_helper = Mage::helper('catalog/category') ?>
    <?php $_categories = $_helper->getStoreCategories() ?>
    <?php if (count($_categories) > 0): ?>
            <ul>
                <?php foreach($_categories as $_category): ?>
                    <li>
                        <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                            <?php echo $_category->getName() ?><?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                            <?php $_subcategories = $_category->getChildrenCategories() ?>
                            <?php if (count($_subcategories) > 0): ?>
                                <ul>
                                <?php foreach($_subcategories as $_subcategory): ?>
                                    <li>
                                        <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                        <?php echo $_subcategory->getName() ?>
                                    </a>
                                    </li>
                                <?php endforeach; ?>
                                </ul>
                            <?php endif; ?>
                        </a>
                    </li>
                <?php endforeach; ?>
            </ul>
    <?php endif; ?>
4
  • This code wil work on level 1 I have to display it for all levels – Paras Arora Mar 14 '16 at 6:02
  • Have a look my edited answer. you'll get 2nd level of all categories/subcategories . – Kaka Mar 14 '16 at 6:09
  • What about Level 3 and Level 4 and so on... – Paras Arora Mar 14 '16 at 6:38
  • If you're getting 1st and 2nd level all categories this way. hope that you'll get others the same way. But.I prefer create a function to get nth level category using above approach. – Kaka Mar 14 '16 at 7:53

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.