Magento Mage::helper('catalog/category')

Magento Mage::helper('catalog/category')

August 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Mage::helper('catalog/category')

Displaying All Magento Categories for Site Tree Navigation

In Magento, by default, Mage::helper('catalog/category')->getStoreCategories() only retrieves categories that are marked as “Include in Navigation Menu”. If you want to display all categories for use in a site tree navigation menu, regardless of the “Include in Navigation Menu” setting, you need to modify your approach.

The current issue lies in using only the category helper. To fetch all categories, we should directly access the category collection from the model instead.

Accessing All Categories Using Magento Model

Here’s how you can retrieve all categories, enabled or disabled:

<?php if(Mage::helper('dynamicsitemap')-&gt;showCategories()): ?>
<div class="sitempan">
    <h2 class="smh2">Our Categories</h2>
    <?php $collection = Mage::getResourceModel('catalog/category_collection'); ?>
    <?php foreach($collection as $_category): ?>
        <!-- Category Listing Here -->
    <?php endforeach; ?>
</div>
<?php endif; ?>

In the code above, Mage::getResourceModel('catalog/category_collection') retrieves all categories in a collection. This includes enabled and disabled categories.

Displaying Subcategories

Let’s modify your existing subcategory logic to work with this new approach:

<!-- Start of Category Listing -->
<?php foreach($collection as $_category): ?>
    <li class="cat">
        <a href="<?php echo Mage::helper('catalog/category')->getCategoryUrl($_category) ?>" title="<?php echo $_category->getName() ?>">
            <strong class="strongsm"><?php echo $_category->getName() ?></strong>
        </a>

        <?php $subcategories = $_category->getChildrenCategories(); ?>
        <?php if (count($subcategories) > 0): ?>
            <ul>
                <!-- Subcategory Listing Here -->
            </ul>
        <?php endif; ?>

    </li>
<!-- End of Category Listing -->

In the updated code, we first retrieve all categories using the collection. For each category, we fetch its subcategories with $_category->getChildrenCategories().

To handle multiple levels of subcategories (as in your original code), you can use nested loops:

<!-- Start of Category Listing -->
<?php foreach($collection as $_category): ?>
    <li class="cat">
        <!-- Category Link Here -->

        <?php $subcategories = $_category->getChildrenCategories(); ?>
        <?php if (count($subcategories) > 0): ?>
            <ul>
                <?php foreach($subcategories as $_subcategory): ?>
                    <!-- Subcategory Listing Here -->
                    <!-- Sub-subcategory Listing Here -->
                <?php endforeach; ?>
            </ul>
        <?php endif; ?>

    </li>
<!-- End of Category Listing -->

In this updated loop, we handle both the first and second levels of subcategories within a single foreach structure.

Conclusion

To display all Magento categories for use in a site tree navigation menu, you need to directly access the category collection using Mage::getResourceModel('catalog/category_collection'). This approach allows you to retrieve enabled and disabled categories. You can then use nested loops to handle multiple levels of subcategories as needed.

Remember to always test your code thoroughly to ensure it works correctly in different scenarios within your Magento store.

For more advanced customizations and best practices, consider checking out the resources at Laravel Company.

Catalog Themes Configuration SEO

Our network