What would be the best concept to create a list of pages (or pages in a certain directory) which have a shared category? Let’s assume the editor gives a product page a category like
category: animal-project (or something else)
And I want to have a page (or dropdown, or widget) where all pages with this category are displayed as a list. What would be the best option?
One. option would. be to display all subpages in that folder by default, and then. have a list of categories. or a select where. the user can select a category and then. filter the list by that category.
Use a select field in your blueprint with a pre-determined set of categories. You can either use global fields for this so you only have one list to maintain, or get the value from a master field that is one page only.
Use the tags field and let people set the category on the fly.
As for the drop down, it’s pretty easy to populate a select field on the front end, or generate a list via filtering if you want some other kind of menu.
Tags is just an example, you can call them whatever you like, category or whatever. Of course, you can apply JS-based sorting as well and just print the category as a class to filter by.
To get a collection from different parents, you can merge them. There are two ways to achieve this:
//Merge two collections
$exhibitions = $pages->find('exhibitions')->children()->visible()->filterB('now', 'noo');
$news = $pages->find('news')->children()->visible();
$homeflux = new Pages(array($exhibitions, $news));
//Appending stuff to a collection:
$homeflux = new Pages();
Then you can loop through the resulting collection with a foreach loop. If you want to use some sort of template. language like in. your example above, you’d have to install a plugin. By default, Kirby uses PHP, not any template language.
Not quite sure what you are talking about. Maybe you can post your structure and indicate what exactly. you want to fetch from where? You can. also check. the. docs for different methods like grandchildren()or index().
Yes, you can combine any pages collection into a single pages collection, but since I don’t. know. what $homeflux is and how you have defined the grandChildren, I can’t really help you with this. If you need more help, please provide the complete code.