ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Can you iterate through categories from a specific point in the hierarchy?

November 20, 2011 3:16am

Subscribe [1]
  • #1 / Nov 20, 2011 3:16am

    jaydisc

    19 posts

    I want to show a group of products that are within a certain branch of their associated category hierarchy. The Category Group has categories similar to this:

    35 Product Line
     |_ 36 Category 1
     |_ 37 Category 2
     |_ 38 Category 3
     |_ 39 Category 4
    40 Another Product Line
     |_ 41 Category 1

    And then the template is like this:

    {exp:channel:categories style="linear" channel="products" show="35"}
    
    <article class="product-item {category_url_title}">
      
     <h1 class="divider">{category_name}</h1>
     
     <table>
      <thead>
       <tr>
        <th>Title</th>
        <th>Product Type</th>
        <th>Code</th>
        <th>ISBN</th>
        <th>Price</th>
        <th> </th>
       </tr>
      </thead>
      <tbody>
       {exp:channel:entries channel="products" category="{category_id}" sort="asc"}
       <tr>
        <td>{title}</td>
        <td>{product_type}</td>
        <td>{product_code}</td>
        <td>{product_isbn}</td>
        <td>{product_price}</td>
        <td><a href="#">Sample ยป</a></td>
       </tr>
       {/exp:channel:entries}
      </tbody>
     </table>
     
    
    </article>
    {exp:channel:categories}

    However, I can’t seem to get it to work as I expect and hope.

    Using the show=“35” parameter of the channel:categories tag only shows that one category (not its children) and all the products are lumped into one iteration of channel:categories in the one table.

    If use show=“36|37|38|39”, that fails, because as the documentation states:

    If you specify that a parent category is not shown, then any children of that parent category are then unable to be shown by the tag. The parent category is required for any and all children categories.

    If use show=“35|36|37|38|39”, it shows the parent category with all the products and then proceeds to iterate through each sub-category correctly showing the breakdown. This has two problems:

    1. I don’t want to show the parent containing everything. It’s redundant.
    2. I ideally don’t want to have to maintain which categories are sub-categories of the product line I’m trying to render.

    Is there no way to pick a point in the Category hierarchy, and only loop through those sub-categories?

    Do I have to create each product line as its own individual Category Group?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases