Magento displays subcategories description on category list.phtml

Magento displays subcategories description on category list.phtml

August 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento displays subcategories description on category list.phtml

Displaying Subcategory Descriptions on Magento Category List.phtml

In Magento, displaying subcategories along with their descriptions on the category page can be achieved by modifying the category list template (list.phtml) and ensuring that the required attributes are fetched from the database. In this post, we’ll guide you through the process of adding subcategory descriptions to your category pages.

Understanding the Issue

You’re currently fetching subcategories using the traditional method in Magento:

<?php if (!$_categoryCollection->count()): ?>
    <p class="note-msg"><?php echo $this->__('There are no subcategories matching the selection.') ?></p>
<?php else: ?>
    <div class="category-products">
        <?php $_collectionSize = $_categoryCollection->count() ?>
        <?php $_columnCount = $this->getColumnCount(); ?>
        <?php $i=0; foreach ($_categoryCollection as $_category): ?>
            <?php if ($i++%$_columnCount==0): ?>
                <ul class="products-grid">
            <?php endif ?>
                <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>" style="width: 214px;">
                    <a href="<?php echo $_category->getUrl() ?>" class="product-image"><img class="photo" src="<?php echo $this->getCategoryImage($_category, 214, 184); ?>" width="214" height="184" alt="<?php echo $_category->getName() ?>" /></a>
                    <strong><?php echo $this->htmlEscape($_category->getName()) ?></strong>
                </li>
            <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
                </ul>
            <?php endif ?>
        <?php endforeach ?>
    </div>
<?php endif ?>

You’ve tried adding the subcategory description using getDescription(), but it’s not being displayed. This happens because the default Magento configuration doesn’t include the ‘description’ attribute when fetching categories.

Fetching Subcategory Descriptions

To fetch the ‘description’ attribute along with other category attributes, you need to modify the public function getChildrenCategories($category) in your app/code/core/Mage/Catalog/Model/Category.php file. Add the following line to select the required attributes:

$this->addAttributeToSelect('description');

The modified function will look like this:

public function getChildrenCategories($category)
{
    $children = $this->_getResource()->getChildrenCategories($category);
    foreach ($children as &$child) {
        if (!empty($child['name'])) {
            $child->setName($this->htmlEscape($child['name']));
        }
        if (!empty($child['description'])) {
            $child->setDescription($child['description']);
        }
    }

    return $children;
}

After adding the addAttributeToSelect('description') line, save the file and clear your cache.

Displaying Subcategory Descriptions in list.phtml

Now that you have fetched the ‘description’ attribute, you can display it on the category page. Open your app/design/frontend/{your_theme}/{your_package}/template/catalog/category/view.phtml file and look for the line where subcategories are being looped:

<?php if (isset($this->getCurrentCategory()->getChildrenCategories())):
    $children = $this->getCurrentCategory()->getChildrenCategories();
?>

Add the ‘description’ field to the loop:

<?php foreach ($children as $_child): ?>
    <a href="<?php echo $_child->getUrl() ?>"><?php echo $_child->getName() ?></a>
    <?php if (!empty($_child->getDescription())): ?>
        <p style="font-size: smaller; color: #666;"><?php echo $_child->getDescription() ?></p>
    <?php endif ?>
<?php endforeach ?>

Conclusion

Displaying subcategory descriptions on Magento category pages involves modifying the category fetching function in app/code/core/Mage/Catalog/Model/Category.php to include the ‘description’ attribute. After updating this file, you can display the description in your list.phtml template by checking if it’s not empty and using getDescription().

Remember to clear your cache after making changes to Magento core files. If you’re looking for more advanced customization options or have other questions about Magento development, feel free to explore our resources on Laravel Company.

Catalog Database Themes Admin

Our network