Forum

Thread tagged as: Question, Configuration

List Items within Category

I am able to list all the categories within a set, using:

<?php perch_categories(array(
  'template' => 'videoCategoryList.html',
  'set' => 'videos',
)); ?>

Here is the template:

<h4><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h4>
<perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" />

But I would like to list all the items within each category. Put simply, I'd like to have a list of all categories in a set, with the items in that category list below it.

Is there a way to do this? Many thanks in advance. Jared

Jared Medley

Jared Medley 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are items in multiple categories?

Yes there will be items in multiple categories.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Should the items be relisted once per category?

Yes, for example, I want to show lists by category on a video library page. I'd like to show all the how-to videos, then list all the featured videos below, etc. I'm rebuilding this page: https://www.handiquilter.com/videos/, which was not built in perch originally. So yes, some videos will be listed in more than one category.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Sounds pretty straightforward then. Use skip-template to get your categories, and then loop through and pull the videos for each category.

Sorry I'm a little dense on this, but when I add 'skip-template' => true, to the array above, nothing is returned. I'm not sure what you mean by loop through and pull the videos. Thanks for the help.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me what you've got?

<?php perch_categories(array( 'set' => 'videos', 'template' => 'videoList.html', 'skip-template'=> true, )); ?>

Thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to assign the result to a variable in order to use it.

$result = perch_categories([
    'set' => 'videos', 
    'skip-template' => true,
]);