Forum
Products from collection with multiple categories
I have a page that is displaying the products for each category using the following code:
<?php
perch_collection('Products', [
'category' => 'product-sector/'.perch_get('cat'),
'template' => 'collections/product_sector.html',
]);
?>
On the template 'product_sector.html', I am trying to pull in the current category title:
<h2><perch:categories id="product_sector" label="Product Sector"><perch:category id="catTitle" /></perch:categories></h2>
The issue I have is products can have multiple categories, so on the page I am getting all categories associated with the first item listed in the <h2> e.g. Cat A, Cat C etc
Can someone point me in the right direction to just pull in the current category?
Andy, It seems like I remember this kind of filter has something to do with catDepth, just something to research while waiting for another reply.
By current, do you mean the one you have the slug for as
perch_get('cat')
?Hi Drew,
Yes, exactly that.
Hi Robert, Thanks for the info - I have been looking in to this as well but I haven't got a working solution as yet.
Hi Drew,
Did you have a solution at all?
Yes, you can use
perch_category(perch_get('cat'))
to get details of that specific category.Sorry Drew, Accidentally pressed 'mark as solution' instead of quote.
Im not sure how to implement this
perch_category(perch_get('cat'))
in the code I posted?If you want to do it in a template instead, you can pass the slug you have into the template and then compare it with a
perch:if
tag within theperch:categories
tags.Hi Drew,
Thanks for the info. For others, here is what i did to get this working:
On the page:
In the template: