It works well, but looks like it shows only the tags of projects, that are in view. For example, when I go to /projects/, then I see all tags, when I filter by some tag, then only those tags are left, that are in filtered projects.
How can I show all tags after applying tag filter?
The problem i think is this bit, because it changes as you move through the pages, since $page means this page (as in, the one you are currently looking at)
// fetch the basic set of pages
$projects = $page->children()->listed();
I think if you give it a fixed point it will stop that…
// fetch the basic set of pages
$projects = $site->find('YOURPROJECTPARENTPAGE')->children()->listed();
Tried chaning to: $projects = $site->find('projects')->children()->listed();
and result is the same, By the way, to make this change work, if I understand right, I also had to change top part to: return function($site, $pages, $page) {
Well, the above should work, it’s come from my own site. All I can suggest is working through “make a blog” cook book guide, since this is explained in there.
<?php
return function($page) {
// fetch the basic set of pages
$projects = $page->children()->listed();
// to get all tags of all projects, put it here
// fetch all tags
$tags = $projects->pluck('tags', ',', true); // set to true to only get unique tags
// add the tag filter
if($tag = urldecode(param('tag'))) {
$projects = $projects->filterBy('tags', $tag, ',');
}
return compact('projects', 'tags', 'tag');
};
In your template, don’t repeat code, but use the $tags variable throughout: