I’m trying to have a page called Projects where all Projects are shown and not grouped or sorted. Every project can get one or more tags.
Now I would like to group those projects by their tags and show one project group on each reload on the Home page. Since a project can have more than one tag, it is possible, that one project is in more than one group.
Project 1 – Tags: Red, Green
Project 2 – Tags: Red
Project 3 – Tags: Green
Project 4 – Tags: Green, Blue
Project 5 – Tags: Red
Groups: Red, Green, Blue
Finally the shown and grouped projects on the home page would be limited to 3 and each page reload, a random other group will be shown. So in the end, the groups contain 3 random projects with one tag which they have in common.
One idea was, that I just sort the projects based on the similar tags and then show the first 3 of this sorted list. Then I would only need to shuffle this sorted list every page reload, right?
I have this projects-snippet:
<?php foreach ($projects as $project): ?>
<section class="swiper-container">
<div class="swiper-wrapper">
<?php foreach ($project->images()->sortBy('sort') as $image): ?>
<div class="swiper-slide">
<?= $image ?>
</div>
<?php endforeach ?>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</section>
<?php endforeach ?>
The snipped above is then used on the Home page like this:
<?php snippet('header'); ?>
<div class="wrapper projects">
<?php snippet('projects', [
'projects' => page('projects')
->children()
->listed()
->sortBy('tags', 'tag', ',')
->limit(3)
]); ?>
</div>
<?php snippet('footer'); ?>
I’m new to Kirby and php and searched the forum for similar problems. I tried to work with sortBy, filterBy and groupBy, but it always seems that I miss something to make it really work. Would the Similar Plugin be a necessary tool for that?