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!