Forum

Thread tagged as: Question, Runway

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">&#x27A1;</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">&#x1F4D3;</i></span>
                        <perch:content id="title" type="text" label="Title" order="1" required="true" title="true" />
                        </a>
                    </li>

</perch:every>
Dan Lee

Dan Lee 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Setting a count option will control the number of Knowledge Articles items returned.

Dan Lee

Dan Lee 1 points

Indeed it does. However it places a limit on all items not items by category which is what I'm seeking to do.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you give an example?

Dan Lee

Dan Lee 1 points

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.

collection items listed by category

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think only you can see that image - I'm getting a 403 Forbidden.

Dan Lee

Dan Lee 1 points

Sorry - ok the image should be showing now.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you'd need to approach this by fetching the categories, and then displaying 5 items for each.