Forum
How do I display Collection Item Limit when Listed by Category?
I have a Collection with categories.
On a Collection page I am displaying the Collection's items by category. Setting count on the bellow function would limit the categories - is there a way of placing a limit on the collection items themselves per category?
knowledge_base.php
<?php
perch_collection('Knowledge Articles', [
'template' => 'cpi/listings/knowledge_archive.html',
'sort' =>'_category',
]);
?>
knowledge_archive.html
<perch:if different="categories">
<perch:if exists="perch_item_first">
<perch:else />
</ul>
</div>
</div>
</div>
</perch:if>
<div class="large-6 small-12 columns">
<div class="card card-5">
<h3>
<perch:categories id="categories" set="departments">
<a href="/knowledge-base/<perch:category id="catSlug" type="slug" />" class="p-category">
<perch:category id="catTitle" type="text" />
</a>
</perch:categories>
</h3>
<div class="card__menu">
<ul class="side-nav">
<li>
<perch:categories id="categories" set="departments">
<a href="/knowledge-base/<perch:category id="catSlug" type="slug" />">
<span class="cat__icon"><i class="ss-icon">➡</i></span>
View All Articles
</a>
</perch:categories>
</li>
</perch:if>
<perch:every count="-n+5">
<perch:else />
<!-- Can I place a function in here? -->
<li>
<a href="/knowledge-base/<perch:categories id="categories" set="departments"><perch:category id="catSlug" type="slug" /></perch:categories>/<perch:content id="titleSlug" type="slug" for="title" label="Slug" editable="true" order="2" />">
<span class="cat__icon"><i class="ss-icon">📓</i></span>
<perch:content id="title" type="text" label="Title" order="1" required="true" title="true" />
</a>
</li>
</perch:every>
Setting a
count
option will control the number ofKnowledge Articles
items returned.Indeed it does. However it places a limit on all items not items by category which is what I'm seeking to do.
Can you give an example?
The following screen shot shows the context of what I'm trying to achieve.
It currently shows a count of 3 collection items listed across 2 categories. We want to show 5 items in each category to be displayed.
I think only you can see that image - I'm getting a 403 Forbidden.
Sorry - ok the image should be showing now.
I think you'd need to approach this by fetching the categories, and then displaying 5 items for each.