Category Filter Help

  • I’m getting very confused (very easy to achieve!) by categories. I have a page which is displaying a category set, this includes links to the contained categories.


    Example, cat set strengthening, this set includes categories such as, Neck, Elbow etc…


    When someone clicks on Neck, I want a page to display all the items that are categorised as Neck. If they click on Elbow, everything categorised as Elbow appears. etc.


    Here is where I am at currently, tried various methods, such as trying to filter, sort and so on without success.


    PHP: Current Template
    1. $template    =    'strengthening/list.html';
    2. perch_collection('Strengthening', [
    3. 'template' => $template,
    4. 'category' => array('strengthening/neck', 'strengthening/shoulder-girdle', 'strengthening/elbow', 'strengthening/wrist-and-hand', 'strengthening/thoracic-spine', 'strengthening/lumber-spine', 'strengthening/gluteals', 'strengthening/hip', 'strengthening/knee', 'strengthening/ankle', 'strengthening/foot', 'strengthening/functional-mobility'),
    5. 'filter' => 'catSlug',
    6. 'match' => 'eq',
    7. ]);


    This template, displays all my categories regardless of filtering and sorting. Hence I think this my issue has something to do with category => array, but what should be in its place?


    Thanks in advance

  • Hi, thank you for the responses and I now realise I haven't explained the "issue" very well.


    I previously found and read the Filtering article, and it did move me towards an answer. The article has two methods as an example. Show a single category, or display all categories.


    I wish to display a single category on my Collection -> Index page. However, this page changes in accordance with the catSlug clicked. Hence the page dynamically changes.


    I have a URL Pattern set on this page which is strengthening/category/[slug:cat].


    To hopefully illustrate further. In the Blog App, if you have Categories listed, you can click the Category link, and then a Page (Blog Archive) is presented with only those Blog articles that match that category. This is what I am trying to achieve, however, with a collection.


    Apologies for not articulating this very well in the first instance. Fingers crossed, this is now corrected.

  • The Blog app doesn't require you to use the full category path. It prefixes the category path with blog/ under the hood.


    Elsewhere in Perch, you can filter items by multiple categories from different category sets. So you need to use the full category path e.g. strengthening/neck/.



    PHP
    1. if(perch_get('cat')) {
    2. perch_collection('Strengthening', [
    3. 'category' => 'strengthening/' . perch_get('cat') . '/'
    4. ]);
    5. }