Display all sub category product when click main category in magento?

Display all sub category product when click main category in magento?

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Display all sub category product when click main category in magento?

Displaying Subcategory Products in Magento

In Magento, displaying products of a subcategory when the parent category is clicked requires setting up the navigation hierarchy correctly and using Magento’s built-in category listing functionality.

Understanding the Category Structure

In Magento, categories are arranged hierarchically, with main categories containing subcategories. Each subcategory can contain its own set of products.

The structure looks like this:

Main Category
- Subcategory 1 (Products)
-- Product 1
-- Product 2
- Subcategory 2 (Products)
   -- Product 3

Setting Up the Navigation

To display all products of a subcategory when the main category is clicked, you need to ensure that your navigation menu is set up correctly.

Navigate to Catalog > Categories and select your main category. Under the Display Settings, make sure the following options are enabled:

  • Is Active: Yes
  • Include in Navigation Menu: Yes

Now, add your subcategories to this main category by clicking on Add Subcategory. Select each subcategory you want to associate with the main category.

Displaying Products in a Subcategory

Magento automatically displays all products assigned to a specific category using the built-in category listing page. When you click on a main category, Magento will redirect to the category view page (URL format: http://yourdomain.com/your-main-category).

The subcategories and their respective products are displayed by default in the category view page.

Here’s an example of what the output might look like:

**Subcategory Name (Subcategory 1)**

Product Name 1
Product Name 2

**Subcategory Name 2**

Product Name 3

Customizing the Layout and Design

To customize the layout or design of these category pages, you can use Magento’s template files. The main file to look at is app/design/frontend/package/theme/Magento_Catalog/templates/category/view.phtml.

This file contains the PHP code that generates the HTML for the category page.

For example, to add a specific CSS class to the subcategory heading, you can modify this line in the view.phtml file:

<div class="page-main">
    <div class="container">
        <h1><?php /* @escapeNotVerified */ echo $block->getTitle() ?></h1>

You could add a CSS class like this:

<div class="page-main">
    <div class="container">
        <h1 class="subcategory-heading"><?php /* @escapeNotVerified */ echo $block->getTitle() ?></h1>

Remember to clear your cache after making changes.

Conclusion

Displaying subcategory products when a main category is clicked in Magento involves setting up the category hierarchy correctly and using the built-in category listing functionality.

By ensuring that your navigation menu is enabled, associating the correct subcategories with each main category, and potentially customizing the template files for the category view page, you can achieve this feature easily without needing complex programming.

For more advanced customizations or if you need assistance with theme development, feel free to reach out to our expert team at LaravelCompany.com.

Catalog Configuration CLI

Our network