0

My category group looks like this:

  • car seats
  • strollers
    • travel systems
  • gear
    • walkers
    • swings
  • nursery

When I'm on the URL /products/category/gear, I want to display:

  • gear (here)
    • walkers
    • swings

When I'm on the URL /products/category/walkers, I still want to display:

  • gear
    • walkers (here)
    • swings

I don't want to display the entire category group, just the current category's parent and/or children and/or siblings.

  • Probably GWcode Categories will not be enough. You also should give a look to GWcode CatMenue and GWcode HasChildren, eventually combining them. Link to GWcode-Addons-page: gwcode.com/add-ons – BNetz Apr 22 '14 at 10:12
1

I think NSM Categories, with its target_category param and {category_is_target} tag, could help. Also, Seg2Cat is useful for grabbing an ID from the category name in the URI.

| improve this answer | |
0

Here's how I ended up doing it:

I used an embedded template and passed the current category ID as a variable:

{embed='_products/category_breadcrumb' cat_id='{if triggers:parent_cat_id_1}{triggers:parent_cat_id_1}{if:else}{triggers:cat_id_1}{/if}'}

The Zoo Triggers variable returns blank if the current category has no parent (meaning it's a top-level category), so I had to use a conditional to output the category ID if the current category is top-level.

Then in my embedded template:

{exp:gwcode_categories
  cat_id='{embed:cat_id}'
  style='linear'
}
  {if results_total > 1}
    {if cat_count == 1}
      <p class="category-filter">
        View: 
    {/if}

    {if cat_url_title == triggers:segment_3}
      <span class="here">{if depth == 1}All{/if}{if depth == 2}{cat_name}{/if}</span>
    {/if}

    {if cat_url_title != triggers:segment_3}
      <span><a href="{path='products/category/{cat_url_title}'}">{if depth == 1}All{/if}{if depth == 2}{cat_name}{/if}</a></span>
    {/if}

    {if cat_count == results_total}
      </p>
    {/if}
  {/if}
{/exp:gwcode_categories}

The caveat is that it only works with a 2-level category tree, but that's all I need for my specific situation.

I'm using the Zoo Triggers {triggers:parent_cat_id_1} and {triggers:cat_id_1} variables, but you could do the same thing with Low Seg2Cat {segment_1_category_parent_id} and {segment_1_category_id} variables.

I also used an embedded template to get the parse order right, but I imagine you could use Stash for this too.

| improve this answer | |

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.