Forum
Perch shop category links
Hi, how do I generate category links from my template? I have this in my template..
</perch:before>
<li>
<perch:categories id="category" set="products" label="Category">
<a href="/shop/cards/categories/<perch:category id="catSlug" type="slug" />/">
<perch:category id="catTitle" type="text" />
</a>
</perch:categories>
</li>
<perch:after>
and this in my page...
<? perch_shop_products([
'template' => 'products/category.html',
]); ?>
but am getting every item listed with a category tag. But I just wantt one for each. What am I missing?
Thanks
What do you mean by "every item listed with a category tag" ?
It looks like your template is fairly broken, so that's the first place to start. You should remove the unpaired
</perch:before>
at the start and the<perch:after>
at the end.Hi Drew. When use the perch: show all tag I can see that each link has complete product information behind it. Hence it is retrieving every item within each category. I should have said ID not tag sorry. Because of this I'm getting duplicate links.
I'm just trying to get a working model at the moment so the code is just a part of a template. The main bit is actually between the before after tags.
It is rough and un-styled but I know but I just need to see how things work for now. Thanks!
I should have said that what I'm trying to achieve is user generated links for either a category splash page or a categories dropdown on the navigation. So when a new category is made in the dashboard the new link will appear without further action from the client.
If you're trying to list categories, don't use
perch_shop_products()
- that's for listing products.Use
perch_categories()
Of course, Brilliant! Thank you! ps. What template does this use as default so I can copy and edit to turn them into links?
If you turn on debug you can see all the templates being used:
https://docs.grabaperch.com/docs/installing-perch/configuration/debug/
Got it. Thanks again!