Forum

Thread tagged as: Question

Filtering item listing by category

Hi

I have a detail page with categories listed at the bottom. When a category is clicked it takes you to the category page which lists items related to that category.

This all works fine and it displays all content related to that Category.

What I am also trying to do is filter results by a Category from another Set as well as the one which has been selected on the detail page.

So that when a category is selected on the detail page of an Offer it only returns items which have been assigned to that main category is there a way for me to add the main category in to the category page code below?

<?php    
if (perch_get('cat')) {
  perch_category(perch_get('cat'),array(
    'template'=>'category_single.html'
));
perch_content_custom('Offers', array(
    'template' => 'item_listing.html',
    'page'=>'/detail.php',
    'category' => perch_get('cat'),
    'sort'=>'itemTitle',
    'sort-order'=>'ASC'
));
} else {
  perch_categories();
}
?>

Neil Irwin

Neil Irwin 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is cat on your URL the full category path, or just the slug?

It's the category path.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. So you can just add it in if you use an array.

'category' => ['set1/this', 'set2/that'],

and so on.

Ah rite. I have tried to add that but the way I have used it brings back all items. How do I make it only bring back ones that match both the first set category and the category path passed through?


<?php if (perch_get('cat')) { perch_category(perch_get('cat'),array( 'template'=>'category_single.html' )); perch_content_custom('Offers', array( 'template' => 'item_listing.html', 'page'=>'/detail.php', 'category' => ['setName/mySetItem', perch_get('cat')], 'sort'=>'itemTitle', 'sort-order'=>'ASC' )); } else { perch_categories(); } ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Set

'category-match' => 'all',

Great

Thanks Drew thats it sorted now.


<?php if (perch_get('cat')) { perch_category(perch_get('cat'),array( 'template'=>'category_single.html' )); perch_content_custom('Offers', array( 'template' => 'item_listing.html', 'page'=>'/detail.php', 'category' => ['setName/mySetItem', perch_get('cat')], 'category-match' => 'all', 'sort'=>'itemTitle', 'sort-order'=>'ASC' )); } else { perch_categories(); } ?>