---
title: "Magento 2: How to Display Categories in Alphabetical order Programmatically in Frontend"
url: "https://magecomp.com/blog/magento-2-how-to-display-categories-in-alphabetical-order-programmatically-in-frontend/"
date: "2020-07-24T17:22:58+00:00"
modified: "2025-02-20T08:55:30+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 402
reading_time: "3 min read"
summary: "Hello Magento Techs ?,"
description: "The product categories in alphabetical order helps customers to find the products easily. Learn How to Display Categories in Alphabetical order in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Add Top Links in Magento 2?"
    url: "https://magecomp.com/blog/add-top-links-in-magento-2/"
  - title: "How to Change the Order of Shipping Fields on Checkout Page in Magento 2?"
    url: "https://magecomp.com/blog/change-order-of-shipping-fields-on-checkout-page-magento-2/"
  - title: "Magento 2 Themes: Top 10 Free Responsive Themes for 2026"
    url: "https://magecomp.com/blog/free-responsive-magento-2-themes/"
---

# Magento 2: How to Display Categories in Alphabetical order Programmatically in Frontend

_Published: July 24, 2020_  
_Author: Dhiren Vasoya_  

![Magento 2: How to Display Categories in Alphabetical order Programatically in Frontend](https://magecomp.com/blog/wp-content/uploads/2020/07/How-to-Display-Categories-in-Alphabetical-order-Programmatically-in-Frontend-in-m2-1024x512.webp)

**Hello Magento Techs ?,**

Greetings of the day! Welcome to the MageComp Technical blog series. Today I am here with the most commendable topic, Magento 2: How to Display Categories in Alphabetical order Programatically in Frontend. Catch over our earlier released blog, [How to Set Cart Page Items Custom Notice Message in Magento 2](https://magecomp.com/blog/set-cart-page-items-custom-notice-message-magento-2/).
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Introduction
Products are added to different categories according to their type. Large Magento stores have lots of product categories. Supposing the categories are disorganized. The customer will find it difficult to locate the right product. As a result, the user will leave the site which decreases the business epitome. If these categories are displayed in alphabetical order, it becomes easy for the customers to explore the products. Quick search, quick shopping, and quick returns.
In Magento, sorting product categories from backend is possible with drag and drop. But if you are running with more than 200 categories, drag and drop can be a deadening job. Thus, the store with lots of categories needs to sort in frontend. The following code can help out with How to Display Categories in Alphabetical order Programatically in Frontend. Let’s get started ?
## Steps to Display Categories in Alphabetical order Programatically in Frontend
**Step 1**: Create one file called **di.xml** in the following path
**app\code\VENDOR\EXTENSION\etc\di.xml**

And add this code
```
<preference for="MagentoCatalogModelResourceModelCategory"
type="VENDOREXTENSIONModelCategory"/>
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

**Step 2**: Create another file **Category.php** in the following path
 **app\code\VENDOR\EXTENSION\Model\Category.php**

And simply add this code
```
<?php

declare(strict_types=1);
namespace VENDOREXTENSIONModel;

class Category extends MagentoCatalogModelResourceModelCategory
{
   public function getChildrenCategories($category)
   {
       $collection = $category->getCollection();
       /* @var $collection MagentoCatalogModelResourceModelCategoryCollection */
       $collection->addAttributeToSelect('url_key')
                  ->addAttributeToSelect('name')
                  ->addAttributeToSelect('all_children')
                  ->addAttributeToSelect('is_anchor')
                  ->addAttributeToFilter('is_active',1)
                  ->addIdFilter($category->getChildren())
                  ->setOrder('name',MagentoFrameworkDBSelect::SQL_ASC)
                  ->joinUrlRewrite();
       return $collection;
   }
}
?>
```

That’s the way.
## Conclusion
I hope, now you are well aware of How to Display Categories in Alphabetical order Programatically in Frontend for your Magento 2 store. Any issues feel free to let me know in the comment section below. I would like to solve it for you. Also, share the article with your friends to help them with the same. Stay in the know!
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding ?**


---

_View the original post at: [https://magecomp.com/blog/magento-2-how-to-display-categories-in-alphabetical-order-programmatically-in-frontend/](https://magecomp.com/blog/magento-2-how-to-display-categories-in-alphabetical-order-programmatically-in-frontend/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-08 05:49:12 UTC_  
