Search code examples
categoriesbigcommercepdp

bigcommerce display a product's categories on product display page


Looking to display all the categories that the specific product is in, on it's product display page. (in code for all products of course)

trying to get stencil's code for displaying like:

each top level category and then the subcategories within it. I have tried code for categories, but not seeming to work on product page.


Solution

  • You can list out the categories that a product is in on the PDP using product.category. However, since this is an array, you will probably want to loop through it and give it some formatting. Here is an example:

    <ul>
      {{#each product.category}}
        <li>{{this}}</li>
      {{/each}}
    </ul>
    

    If you only want to show the child categories (not the parent category), try this code:

    <ul>
      {{#each product.category}}
        <li>{{last (split this '/')}}</li>
      {{/each}}
    </ul>
    

    Reference: https://developer.bigcommerce.com/theme-objects/product