How To

How to get sub category details using main category URL key in Magento 2

In the early days of Ecommerce, products are listed directly on the homepage either in list view, and remaining options or filters displayed in a left-column. But over a time with growing use of the internet, people are more tending to shop online instead of walking to the nearest shop. To comply with the trend and increase online shopping sales by serving tons of options to customer needs, shop owners started dividing shop products into multiple categories and subcategories that make easy for the customer to find a product from millions of product options.

If Shop owner doesn’t split products into proper categories, store shoppers need to suffer a lot to find a product from the list of options. Also, creating too many categories, subcategories might confuse your customers. To reduce the efforts of shoppers and to implement, easy navigations to throughout the whole store, you can use graphics tiles with suitable category image. Because these categories and subcategories pages are means a lot to gain better ranking over SERP pages we decided to write the blog to display subcategory details under the hood of main category URL key. You can even use this code to find subcategories of the main category.

Firstly, we need to create custom extension and place given code to ‘index.php’ file at below location.
app\code\Vendor\Extension\Block\Index\Index.php


You can play & use this code according to your need of displaying subcategory in respective CMS pages of your Magento 2 store. Tell us in comment section, how you have used this code in your Magento 2 store.
Happy Splitting!

Click to rate this post!
[Total: 3 Average: 3.7]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

Magento 2: Add Quantity Increment and Decrement on Category Page

Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…

21 hours ago

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

4 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

6 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

6 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

1 week ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

1 week ago