---
title: "How to Show List of All Categories with Links at Sidebar on Category Page in Magento 2"
url: "https://magecomp.com/blog/show-list-categories-links-sidebar-category-page-magento-2/"
date: "2020-02-21T17:56:15+00:00"
modified: "2025-02-21T10:27:30+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 560
reading_time: "3 min read"
summary: "Hello, Magento Folks,"
description: "With the help of little bit coding knowledge you can show a list of all categories so the customer can easily navigate from one category to another."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Setup Multi Store in Magento 2 (Updated)"
    url: "https://magecomp.com/blog/setup-multi-store-in-magento-2/"
  - title: "How to Automatically Generate CSV File on Every Order in Magento 2?"
    url: "https://magecomp.com/blog/automatically-generate-csv-file-on-every-order-magento-2/"
  - title: "How to Secure your Magento 2.x Store"
    url: "https://magecomp.com/blog/secure-magento-2-x-store/"
---

# How to Show List of All Categories with Links at Sidebar on Category Page in Magento 2

_Published: February 21, 2020_  
_Author: Dhiren Vasoya_  

![Show Display All Categories with Links on Category page sidebar in Magento 2](https://magecomp.com/blog/wp-content/uploads/2020/02/Show-Display-All-Categories-with-Links-on-Category-page-sidebar-in-Magento-2-1024x512.webp)

Hello, Magento Folks,

Last time we learned how you can **[Remove decimals from quantity in the product grid](https://magecomp.com/blog/magento-2-remove-decimal-quantity-product-grid-magento-admin/)** of Magento 2 admin. Today we are here to explain how you can show the list of all categories with links at the sidebar on the category page in Magento 2.

[![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)

When you need to show all of the categories to the customer, you can do so with the help of coding knowledge. You can show a list of all categories so the customer can easily navigate from one category to another with ease. The following code will add all of the categories with links to the sidebar of the category page.

[![Magento 2 Mobile APP](https://magecomp.com/blog/wp-content/uploads/2022/01/Magento-2-Mobile-APP1.png)](https://mobileapp.magecomp.com/?utm_source=magecomp_blog&utm_medium=mobile_app_banner&utm_campaign=magento_2_mobile_app)

### 1] First, we need to add **2columns-left.xml** file at the following path:

**app\code\Vendor\Extension\view\frontend\page_layout\2columns-left.xml**

```
<?xml version="1.0"?>

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="2columns-left"/>

    <referenceContainer name="columns">
        <referenceContainer name="sidebar.main">
            <block class="VendorExtensionBlockCategorylist" name="category-sidebar" template="Vendor_Extension::category.phtml"/>
        </referenceContainer>
    </referenceContainer>
</layout>
```

### 2] Now you need to add **category.phtml** at the following path:

**app\code\Vendor\Extension\view\frontend\templates\category.phtml**

```
<?php
$category = $block->getEnableCategory();
?>
<h2 align="center">Category list</h2>
<?php foreach ($category as $categorydata) : ?>
    <?php
    $categoryid = $categorydata->getEntityId();
    $categoryFactory = $block->getCategoryName($categoryid);
    $categoryNameshow = $categoryFactory->getName();
    $categoryUrlShow = $categoryFactory->getUrl();
    ?>
            <a class="category-link-show" href="&lt;?php echo $categoryUrlShow; ?" data-wpel-link="internal" target="_blank" rel="follow">" alt="<?php echo $categoryNameshow; ?>"
           title="<?php echo $categoryNameshow; ?>">
                                                <?php echo $categoryNameshow; ?>                                    </a>
    <?php endforeach; ?>
```

### [![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-2.webp)](https://magecomp.com/services/hyva-theme-development/)

### 3] Now You Need to create **Categorylist.php** file at the following path:

**app\code\Vendor\Extension\Block\Categorylist.php**

```
<?php

namespace VendorExtensionBlock;

use MagentoCatalogModelProduct;

class Categorylist extends MagentoFrameworkViewElementTemplate
{
    protected $_categoryFactory;

    protected $_storeManager;

    protected $_categoryNameFactory;

    public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoCatalogModelCategoryFactory $categoryNameFactory,
        MagentoCatalogModelResourceModelCategoryCollectionFactory $collecionFactory,
        MagentoStoreModelStoreManagerInterface $storeManager,
        MagentoFrameworkRegistry $registry,
        array $data = []
    )
    {
        $this->_coreRegistry = $registry;
        $this->_categoryNameFactory = $categoryNameFactory;
        $this->_categoryFactory = $collecionFactory;
        $this->_storeManager = $storeManager;
        parent::__construct($context, $data);
    }

    public function getEnableCategory()
    {

        $category = $this->_categoryFactory->create()->setStore($this->_storeManager->getStore());
        return $category;
    }

    public function getCategoryName($categoryId)
    {
        $category = $this->_categoryNameFactory->create()->load($categoryId)->setStore($this->_storeManager->getStore());
        return $category;
    }
}
```

And that’s it for the day. Using these codes, you will be able to show the list of all categories with links at the sidebar on the category page of Magento 2. Feel free to implement these codes as per your needs. If you face any problem while doing so, then you can contact our **[Support team](https://magecomp.com/support)** for help. We will be happy to help you.

[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-2.webp)](https://magecomp.com/services/hire-magento-programmer/)

Lastly, let us know what you feel about this article in the comment section below. Also, don’t forget to share this with your Magento partners and colleagues.

Happy Coding?


---

_View the original post at: [https://magecomp.com/blog/show-list-categories-links-sidebar-category-page-magento-2/](https://magecomp.com/blog/show-list-categories-links-sidebar-category-page-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-25 14:01:47 UTC_  
