Forum

Thread tagged as: Problem, Runway

Filtering articles collection list by category

I'm trying to list all the articles assigned to a specific category using the following but getting no output:

       perch_collection('Articles', [
          'template'   =>'article-category-list.html',
          'category' => 'categories/overview/good-posture/'
       ]);  

'categories' is the set, 'overview' is a parent category and 'good-posture' a sub-category. If I remove 'category' => 'categories/overview/good-posture/' from the array, all the articles are output regardless of what category they're assigned to, as expected. Any idea why passing the category in the array doesn't work?

Adam Green

Adam Green 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does removing the trailing slash have any impact?

No, still nothing without the trailing slash :( Also tried removing 'categories' with & without the slash, 'good-posture' on its own, etc. Here's the template if that's any help:

<div class="article-box"> 
   <section class="article-topic">
      <h3><a href="/<perch:content id="cat_slug" />/<perch:content id="slug"/>"><perch:content id="title" /></a></h3>
      <perch:if exists="image"><img src="<perch:content type="image" id="image" label="Image" width="800" />" alt="<perch:content type="text" id="alt" label="Image description" required="true" title="true" />" /></perch:if>
      <perch:content type="textarea" id="excerpt" words="40" append="&hellip;" />
      <p><a href="/<perch:content id="cat_slug" />/<perch:content id="slug" />">Read more &hellip;</a></p>
   </section>
</div> 

'cat_slug' is passed from the URL & set as a system variable prior to calling the template.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, what does it output for the page?

All working now - changing something in one of the templates must have caused the issue which was fixed by re-saving all the articles.

On that note, are there any plans for a 'Republish' function / button for collections that would save one having to re-save all articles 1 by 1?

Thanks again for the responses & sorry for the recent forum bombardment!

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the scenario whereby you'd need to save the items one by one?

Not entirely sure but I suspect that changes to one the template files caused the filtering by category to stop working - maybe the content in one of the entries didn't match the ids in the template file? Can't say for sure but it works now & hopefully won't happen again!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great.