0

I'm building a site that has two main channels:

  • Product (this describes a meat, cheese or milk product). The user can then create entries describing the product, then categorise this product as 'milk', 'meat' or 'cheese'
  • Product category (this describes all products of a certain type, i.e. describing how great all the meat products are). This is used to create a category page for each product category the business wants to list.

I've successfully set the templates up so that a main 'products' page is pulling in an image, name and short description for each instance of the 'product category'. You can then click through to each 'product category' and see the name and a long description of the category.

The problem I'm having is how to specify: "Show all instances of 'products categorised as meat' within the 'product category' channel entry for meat" and so on, for each product category

I could create a template for each different kind of product category, but it seems like this should be simple and I'm missing something obvious!

The folder structure is something like this:

/products/product_category/product_name/

Realstically: /products/meat/smoked-bacon

/products/ - Lists product categories

/meat/ - Lists everything categorised with 'meat' (this is the bit I'm struggling with)

/smoked-bacon/ - A product page for smoked bacon

Any help would be appreciated!

Cheers

0

Are you using subcategories? I'd probably go with setting up subcategories for different types, e.g.

Meat (top level category)

-- Bacon (sub category)

-- Ham (sub category)

-- Pork (sub category)

What you can then do is show all products (i.e. the "Meat" category) or narrow down results using a subcategory (i.e. "Bacon").

0

Are your product entries being assigned categories in the admin panel?

If so, assuming the category url_title is the first segment of the url ( domain.com/{category-name} ), and your products channel is named products you should be able to pull all the entries from your categories like this:

{exp:channel:category_archive channel='products' style='linear}
  {categories}
    {if category_url_title == segment_1}
      {exp:channel:entries category='{category_id}'}
        {!-- your entry data and list item template --}
      {/exp:channel:entries}
    {/if}
  {/categories}
{/exp:channel:category_archive}

This will pull all the entries assigned to the category that is named in segment_1 of your url. You can add other parameters to the tag to specify things like limit, offset, pagination, status, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.