Menu Close

Get Support From ShopWired Close

All Systems Are Operational

Subscribe To Updates
Prefer To Live Chat? Chat directly with ShopWired support Available 9.00am to 7.00pm Monday to Friday
11.00am to 5.00pm Saturday
Quickest response time

Send A Message
Response within 24 hours

Menu Close


Displaying products or sub-categories from a specific category

There maybe times where, on a specific page, you would like to display the products or subcategories from a specific category.

For example, you may want to create a landing page on your website for a particular campaign and display the products belonging to a 'special offer' category.

In this guide, we've listed the necessary twig code that you'll need to use to do so.

Note: The guide assumes that you have already created the twig file that renders the page you are creating.

Firstly, you'll need the unique ID of the category whose products/subcategories you want to display. The ID can be located within the management system. When editing a category, your browser's address bar will display a URL like /business/manage-ecommerce-add-category/104729, the final number 104729 is the unique ID of the category.

On the twig page that you want to render the products/subcategories, you'll need to set the category as follows:

{% set your_category = category(104729) %}

The your_category variable can be given any name that you want. Replace the number shown above with the unique ID of your category.

Once you've done this, you'll have access to the category object of the set category, e.g.

{{ your_category.title }}

will return the name of the set category.

You now have access to the product object of every product that belongs to the set category, e.g.

{% for product in your_category.products %}
{{ product.title }}
{% endfor %}

Similarly, you have access to the category object for every category that belongs to the set category, e.g.

{% for category in your_category.categories %}
{{ category.title }}
{% endfor %}