Forum
Paginate categories inside collection
Is it possible to paginate categories that are stored inside a collection item?
For example:
- I have a collection called Flooring Industries, which could be made up of things like Hotels, Retail, Education, etc.
- Each Flooring Industry collection has flooring 'categories' attached to it e.g. Retail might have flooring line categories such as Lines, Stripes, Squares, etc.
I need to show each industry, and its associated categories.
On an example page, Andover and Fernlea are flooring lines (Perch categories) attached to the Serviced Offices collection. I would like to paginate the categories here.
I initially thought that if I paginate the collection this would work, but instead, Perch paginates the collection item. e.g. something like the following would paginate Hotels, Retail, Education, rather than Lines, Stripes, Squares:
perch_collection('Flooring Catalogue Industries', [
'filter' => 'name_link',
'match' => 'eq',
'value' => perch_get('level3'),
'template' => 'flooring_catalogue/industries/industry_categories.html',
'paginate' => true,
'count' => 1,
]);
So what I need to do is paginate the categories inside this collection.
My guess is that:
- I might have missed something obvious and this is easily achieved, or…
- I might need to do something with a callback
Any suggestions appreciated!
Hello Jay,
perch_collection()
gets you Collection items.perch_categories()
gets you Categories. So if you need to paginate Categories, you ultimately need to useperch_categories()
.What you can do in this case is retrieve the Collection items with
perch_collection()
and use theskip-template
option. Grab all the used categories in PHP, then use them to filter the categories withperch_categories()
.Thanks, Hussein! That makes sense.
I'm currently stuck on how to grab just the categories from the array. So I have this:
…which gets me the correct collection record for the page.
How would I drill down further, just to grab the categories from that collection?
Thanks again for your help
You can check what you have with:
Something roughly like this should do the trick:
Here
$item['categories']
refers to$item['field_id']
. So assuming your categories field has the idcategories
:Word processing, desktop publishing, and digital typesetting are technologies built on the idea of print as the intended final output medium, although nowadays it is understood that plenty of the content produced through these pathways will be viewed onscreen as electronic pages by most users rather than being printed on paper. https://mcdvoice.me/
How to use https://iptvlinks.site/ for 2019