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!