0

So I have several Channel Data that I'm pulling into a Product page: Accessories, Options, Features, etc...

For Accessories I have all of the associated products pulled in, but now I want to pull in the categories for each product but only once. When I do this:

{exp:playa:parents channel="products_accessories" field="{{embed:slug}_accessories}" disable="members"}
{categories}<div class="col-md-4">
<p><a href="{url_title_path='products/accessories/'}">{category_name}</a></p>
</div>{/categories}
{/exp:playa:parents}

But that just gives me all the Categories for each product over and over again. Obviously not what I want. I just want to find each Category and list it once along with a link to that product category page :)

Any thoughts?

UPDATE

I have tried this as well:

{exp:channel:category_archive channel="products_accessories"}
    {categories}
            <h3>{category_name}</h3>
    {exp:playa:parents channel="products_accessories" field="{{embed:slug}_accessories}" category="{category_id}" disable="members"}
            <a href="#">{title}</a>
    {/exp:playa:parents}

    {/categories}
{/exp:channel:category_archive}

This gets me all of the entries in the appropriate category but I also get all of the other Categories too. I need a way to pass the Entry IDs that I want to the Category Archive.

UPDATE 2 USING STASH

I have also tried what the might Croxton suggested:

{exp:stash:set_list name="cat_accessories" parse_tags="yes"}
   {exp:playa:parents channel="products_accessories" sort="asc" orderby="title" disable="members"}
      {categories}
         {stash:id}{category_id}{/stash:id}
         {stash:url}{url_title_path='products/accessories/'}{/stash:url}
         {stash:name}{category_name}{/stash:name}
      {/categories}
   {/exp:playa:parents}
{/exp:stash:set_list}

{!-- get unique list items only --}
{exp:stash:get_list name="cat_accessories" unique="yes"}
   <div class="col-md-4">
       <p><a href="{url}">{name} | {id}</a></p>
   </div>
{/exp:stash:get_list}

I'm still just getting the category listed each time an entry loop is parsed (the entry detail page loops it through 6 times):

Category
Category
Category
Category
Category
Category

So I'm not sure what's happening with the unique="yes" parameter on the exp:stash:get_list tag pair.

When I run Template Debugging I get this:

(0.453361 / 16.55MB)      Stash: SET cat_accessories to value id|=|102|&|url|=|http://animalcaresystems.dev/products/accessories/bedding-1-4-corn-cob-nestpacks|&|name|=|Single Use Caging Options|+|id|=|102|&|url|=|http://animalcaresystems.dev/products/accessories/single-use-cage-top-for-sipper-sack|&|name|=|Single Use Caging Options|+|id|=|102|&|url|=|http://animalcaresystems.dev/products/accessories/single-use-cage-top-for-water-bag|&|name|=|Single Use Caging Options|+|id|=|102|&|url|=|http://animalcaresystems.dev/products/accessories/single-use-cage-top-for-water-bottle|&|name|=|Single Use Caging Options|+|id|=|102|&|url|=|http://animalcaresystems.dev/products/accessories/single-use-docking-tray|&|name|=|Single Use Caging Options|+|id|=|102|&|url|=|http://animalcaresystems.dev/products/accessories/single-use-water-bottle-assembly|&|name|=|Single Use Caging Options

I'm assuming that Stash grabs the ID of the category to determine if the Categories are the same?

UPDATE FINAL

With Croxton's help I now have this:

{exp:stash:set_list name="cat_accessories" parse_tags="yes"}
   {exp:playa:parents channel="products_accessories" sort="asc" orderby="title" disable="members"}
      {categories}
         {stash:id}{category_id}{/stash:id}
         {stash:url}{url_title_path='/products/accessories/'}{/stash:url}
         {stash:name}{category_name}{/stash:name}
      {/categories}
      {stash:product_title}{title}{/stash:product_title}
      {stash:product_image}{if products_accessories_images}<div class="accessories_image">{products_accessories_images limit="1"}<p><img src="{exp:ce_img:single src='/images/uploads/products/{image}'{sn_image_product_detail_accessories}}" alt="{alt}" class="img-responsive text-center" />{/products_accessories_images}</p></div>{/if}{/stash:product_image}
      {stash:product_content}{if products_accessories_content}<p>{exp:eehive_hacksaw chars='175'}{products_accessories_content}{/exp:eehive_hacksaw}</p>{/if}{/stash:product_content}
   {/exp:playa:parents}
{/exp:stash:set_list}

{!-- get unique list items only --}
{exp:stash:get_list name="cat_accessories" unique="id"}
    <h3>{name}</h3>
    <div class="col-md-4 accessories_listings">
        <p><a href="{url}">{product_title}</a></p>
        {product_image}
        {product_content}
    </div>
{/exp:stash:get_list}

The last thing I need is just all of the Products under that Category. I'm only getting ONE product although there are SIX under this particular category.

GETTING ALL PRODUCTS UNDER CATEGORY WITH STASH

Missing Getting Products JUST in it's Category (almost there!)

Okay I think I have what I want, please let me know if there's a better way of doing this :)

{exp:stash:set_list name="cat_accessories" parse_tags="yes"}
   {exp:playa:parents channel="products_accessories" sort="asc" orderby="title" disable="members"}
      {categories}
         {stash:id}{category_id}{/stash:id}
         {stash:name}{category_name}{/stash:name}
      {/categories}
   {/exp:playa:parents}
{/exp:stash:set_list}

{exp:stash:set_list name="product_info" parse_tags="yes"}
   {exp:playa:parents channel="products_accessories" sort="asc" orderby="title" disable="members"}
      {stash:product_url}{url_title_path='/products/accessories/'}{/stash:product_url}
      {stash:product_title}{title}{/stash:product_title}
      {stash:product_image}{if products_accessories_images}<div class="accessories_image">{products_accessories_images limit="1"}<p><img src="{exp:ce_img:single src='/images/uploads/products/{image}'{sn_image_product_detail_accessories}}" alt="{alt}" class="img-responsive text-center" />{/products_accessories_images}</p></div>{/if}{/stash:product_image}
      {stash:product_content}{if products_accessories_content}<p>{exp:eehive_hacksaw chars='175'}{products_accessories_content}{/exp:eehive_hacksaw}</p>{/if}{/stash:product_content}
   {/exp:playa:parents}
{/exp:stash:set_list}

    {!-- get unique categories items only --}
    {exp:stash:get_list name="cat_accessories" unique="id"}
        <h3>{name}</h3>
        {!-- get products that belong to this category --}
        {exp:stash:get_list:nested name="product_info" parse_tags="yes"}
        <div class="col-md-4 accessories_listings">
            <p><a href="{product_url}">{product_title}</a></p>
            {product_image}
            {product_content}
        </div>
    {/exp:stash:get_list:nested}
{/exp:stash:get_list}

Thanks again for all of the help!

1 Answer 1

2

Each related product could have individual category relationships, right? So If I understand you correctly, you want the aggregate of all categories assigned to the related entries.

You can do that with Stash:

{exp:stash:set_list name="cat_accessories" parse_tags="yes"}
   {exp:playa:parents channel="products_accessories" field="{{embed:slug}_accessories}" disable="members"}
      {categories}
         {stash:id}{category_id}{/stash:id}
         {stash:url}{url_title_path='products/accessories/'}{/stash:url}
         {stash:name}{category_name}{/stash:name}
      {/categories}
   {/exp:playa:parents}
{/exp:stash:set_list}

{!-- get unique list items only --}
{exp:stash:get_list name="cat_accessories" unique="yes"}
   <div class="col-md-4">
       <p><a href="{url}">{name}</a></p>
   </div>
{/exp:stash:get_list}

EDIT

Aha, so you're url is dependent on the entry url title, not the category url title, and is therefore unique even for same categories. Is that intentional?

If you change unique="yes" to unique="id" (i.e. the id column must be unique) then you'll get only unique categories, however I'm not sure what you need to do with that url.

EDIT 2

You can use nested lists and match/against to list out unique categories and associated products. No need to repeat your Playa loop twice:

        {exp:stash:set_list name="product_info" parse_tags="yes" parse_depth="2"}

           {exp:playa:parents channel="products_accessories" sort="asc" orderby="title" disable="members"}

                {stash:product_url}{url_title_path='/products/accessories/'}{/stash:product_url}
                {stash:product_title}{title}{/stash:product_title}
                {stash:product_image}{if products_accessories_images}<div class="accessories_image">{products_accessories_images limit="1"}<p><img src="{exp:ce_img:single src='/images/uploads/products/{image}'{sn_image_product_detail_accessories}}" alt="{alt}" class="img-responsive text-center" />{/products_accessories_images}</p></div>{/if}{/stash:product_image}
                {stash:product_content}{if products_accessories_content}<p>{exp:eehive_hacksaw chars='175'}{products_accessories_content}{/exp:eehive_hacksaw}</p>{/if}{/stash:product_content}

                {!-- create an index for this product to match against --}
                {stash:categories}{categories}@{category_id}@{/categories}{/stash:categories}

                {categories}
                    {exp:stash:append_list name="cat_accessories"}
                        {stash:cat_id}{category_id}{/stash:cat_id}
                        {stash:cat_name}{category_name}{/stash:cat_name}
                    {/exp:stash:append_list}
                {/categories}

           {/exp:playa:parents}

        {/exp:stash:set_list}


        {!-- list unique categories only --}
        {exp:stash:get_list name="cat_accessories" unique="cat_id" orderby="cat_name" sort="asc"}

            <h3>{cat_name}</h3>

            {!-- list products that belong to this category --}
            {exp:stash:get_list:nested name="product_info" match="#@{cat_id}@#" against="categories" orderby="product_title" sort="asc"}
            <div class="col-md-4 accessories_listings">
                <p><a href="{product_url}">{product_title}</a></p>
                {product_image}
                {product_content}
            </div>
            {/exp:stash:get_list:nested}
        {/exp:stash:get_list}
3
  • That nearly works, it just outputs each Product Category each time, so it looks like that unique="yes" parameter isn't working or something. Commented Apr 3, 2014 at 16:31
  • Sweet your updated one works! Now I just need to get the products below the Category Name too then I'm good to go! Commented Apr 3, 2014 at 17:48
  • Updating my Question one last time (hopefully) regarding getting the Products to appear in its appropriate category. Currently all products are showing up under all the categories. Commented Apr 3, 2014 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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