Fetching data from different pages at once (using tags)

I am working on a website where all the content (images, files …) has several tags. All the tags are displayed as a list and you use them to navigate the content, the idea is be able to use them combined. So for example selecting the tags ‘book’, ‘2021’ and ‘red’ and all the content related to these tags from all the projects will be displayed.

As I understand that would be very easy to achieve using a database CMS but in Kirby I don’t know if it is possible to query from different pages at once and also combine.

The current structure is:

Projects
	Project A
		File A-1 (tag-A, tag-C)
		File A-2 (tag-B, tag-C)
	Project B
		File B-1 (tag-B)
		File B-2 (tag-A, tag-C)		
	Project C
		File C-1 (tag-C)
		File C-2 (tag-A, tag-B)
  1. So in the page I have the list of tags displayed:
    Tag-A, Tag-B, Tag-C

  2. And if I click on the Tag-B for example, all the files matching that tag from all the pages will be displayed.

  3. In this case:
    File A-2, File B-1, File C-2

Is this possible?

Thanks!

You can fetch all files of the subpages with

$files = page('projects')->children()->files();

You can then filter the files:

$filesWithTagA = $files->filterBy('tag', 'Tag-A', ',');

This is just an example. You would replace the hard-coded 'Tag-A` with your variable, of course.

Thank you, that helped but I am not sure how to use this method for multiple tags.

I am currently displaying the tags as links and sending the “tag” through the URL as I found here in the documentation.

"<a href='" . $site->url() . "/tag:" . $tag . "'>" . $tag . " </a> ";

But I am not sure how this method can work for fetching several tags.

The idea is that once you click one and the content displayed you could click another one and the files will be added with the ones already displayed from the previous selection.

IMO, using anker tags is not the right approach for filtering by multiple tags. Better use a form with checkboxes, or some JS solution if necessary.