Show Product Categories in the Storefront
List product categories for navigation.
On this page
In this guide, you'll learn how to show a list of product categories in the storefront. You'll also learn how to paginate and filter them.
Good to know: Product categories allow you to organize similar products together and within a hierarchy. For example, you can have a "Shoes" category grouping together all different types of shoes. You can then allow customers to browse products by category.
List Product Categories
To retrieve the list of product categories, send a request to the List Product Categories API route:
Tip: Learn how to install and configure the JS SDK in the Getting started guide.
React
tsx
JS SDK
ts
In this example, you send a request to the List Product Categories API route.
The response has a product_categories field, which is an array of product categories.
Paginate Product Categories
To paginate product categories, pass the following query parameters to the List Product Categories API route:
limit: The number of product categories to return in the request.offset: The number of product categories to skip before the returned product categories. You can calculate this by multiplying the current page with the limit.
The response object returns a count field, which is the total count of product categories. Use it to determine whether there are more product categories that can be loaded.
For example:
tsx
In this example, you send a request to the List Product Categories API route with the limit and offset query parameters.
The response object returns a count field, which is the total count of product categories. Use it to determine whether there are more product categories that can be loaded.
If there are more product categories, you show a button to load more product categories on click.
Filter Categories
The List Product Categories API route accepts query parameters to filter the categories by description, handle, external_id, and more.
Refer to the API reference for the full list of accepted query parameters.
For example, to filter the categories by with a search query:
ts
By passing the q parameter, you can search through the categories' searchable fields, including their title and description.
To filter by external ID:
This feature is available since the current Aiminaabee API.
ts
Sort Categories
To sort categories by a field, use the order query parameter. Its value is a comma-separated list of fields to sort by, and each field is optionally prefixed by - to indicate descending order.
For example, to sort categories by name in descending order:
ts
The result will be categories sorted by name in descending order.