Magento Admin Category tree

Magento Admin Category tree

October 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Admin Category tree

Displaying Magento Category Tree on Non-Admin Pages

As a senior developer specializing in e-commerce platforms like Magento, I often receive questions about customizing the admin interface for better user experience or to extend functionality to non-admin pages. One of the most common requests is to display the category tree that exists in the admin menu somewhere else on the admin side without using custom JavaScript.

In this post, we’ll explore how you can achieve this using Magento’s built-in functions and core files. This approach keeps your code clean, maintainable, and ensures compatibility with future updates.

Understanding the Category Tree Structure

The category tree in Magento is stored as a nested set of records in the catalog_category_entity table. Each node represents a category and contains metadata like name, description, and parent ID. The hierarchy is maintained by the relationship between the parent and child nodes’ IDs.

Retrieving the Category Tree Data

To display the category tree on another admin page, you’ll need to retrieve this data from the database. Magento provides several models that can help with this task:

  1. magento\catalog\Model\Category
  2. magento\catalog\Model\ResourceModel\Category

The Category model is a simple data access object (DAO) that allows you to fetch category data using various methods like load($categoryId), getChildrenCategories(), etc.

For more complex queries and tree traversals, you would typically use the ResourceModel_Category model. This extends the Eav_Mysql4_Entity_Abstract class and provides methods for retrieving categories based on filters and sorting options.

Displaying the Category Tree Using Magento’s Core Functions

To display the category tree without writing custom JavaScript, you can leverage Magento’s built-in functions that generate the admin menu. The core file responsible for this is app/code/core/Mage/Adminhtml/Block/Menu.php.

The getChildren() function in this block retrieves the submenu items based on the current node. You can use a similar approach to fetch category nodes and build your tree structure.

Here’s a high-level example of how you might achieve this:

public function getCategoryTree()
{
    $rootNodeId = 1; // Assuming 0 is the root node for categories

    $categoryCollection = Mage::getModel('catalog/category')
        ->getCollection()
        ->addFieldToFilter('parent_id', array($rootNodeId))
        ->setOrder('position');

    return $this->_buildCategoryTree($categoryCollection);
}

private function _buildCategoryTree($collection)
{
    // Implement logic to build the category tree structure
    // Use the getChildrenCategories() method of each category object to fetch sub-categories

    return $tree;
}

In this example, we first retrieve the root node using a hardcoded ID (1 in this case). You can modify this based on your specific use case. The function then fetches all child categories under the root node and orders them by position.

The _buildCategoryTree() method is where you would implement the logic to traverse the category collection and construct the tree structure recursively using PHP arrays or object-oriented data structures like a nested set.

Displaying the Category Tree on Non-Admin Pages

To display this category tree on non-admin pages, you’ll need to include it in your layout XML file. You can use the adminhtml layout handle if you want the tree to appear only on admin pages or create a custom layout handle for more control over its visibility.

Here’s an example of including the category block in your layout:

<reference name="content">
    <block type="core/text_list" name="category.tree">
        <action method="setTemplate"><template>page/html/categories.phtml</template></action>
        <block type="your_module/category_tree" template="your_module/categories.phtml"/>
    </reference>
</reference>

In this example, replace your_module with the actual module name where you have created your category tree block. The categories.phtml file should contain the PHP code that generates the tree structure.

Conclusion

Displaying a Magento admin menu on non-admin pages is a common requirement for extending functionality and creating custom interfaces within the admin section. By leveraging Magento’s built-in models, core files, and layout handles, you can achieve this without resorting to custom JavaScript or complex database queries.

Remember that this approach assumes you have access to the Magento codebase and are familiar with its architecture and file structure.

For more detailed guides on customizing Magento admin interfaces and extending functionality, I recommend checking out our comprehensive tutorials at LaravelCompany. We cover topics like creating custom admin modules, modifying layout XML files, and optimizing performance for large-scale e-commerce sites.

Happy coding!

Catalog Database Admin SEO

Our network