Magento 2 – Show Subcategories and Products on Category Page

categorymagento2static-block

It's a common question how to show subcategories above the products on any given category view. In Magento 1 it was fairly straight forward; create a static block, add the necessary code to the template and show that block along with the products on said category.

But Magento 2 is quite different, and I figured out I could use two approaches:

  • Create a module which does it for me
  • Create a static block and show it with the category

For the first approach I found this code/module and this code which I applied to the category pages via XML, but it shows all the categories, in stead of only the current categories sub's. I tried to edit this but couldn't get it to work.

For the second approach, I figured I create a static block and assign it to the category in the adminpanel. All I did so far was create the static block, and what happens? It shows on every page in every sidebar and content block (so double on each page). This might be considered a separate question, but does anyone know why this happens?

Best Answer

I found the answer here, in another question. To clarify further; I went with the first approach, created a simple module and used the code from the said answer in my view/frontend/templates/subcategories.phtml Then I use a custom layout update XML in the adminpanel for the categories where I want the code to show.

Related Topic