Hi there ![]()
I’m new to Kirby, and new to php.
I tried to apply the cookbook about tag filtering : Filtering with tags | Kirby CMS
What I want to do :
- on the article page, defined tags should show. This is ok.
- when clicking on a tag, it should show a page with all articles that have that tag. This doesn’t work.
Here is my ‘article’ template :
<aside>
<p>Étiquettes</p>
<ul class="tags">
<?php foreach($tags as $tag): ?>
<li>
<a href="<?= url($page->url(), ['params' => ['tag' => $tag]]) ?>">
<?= html($tag) ?>
</a>
</li>
<?php endforeach ?>
</ul>
</aside>
And here is the ‘article’ controller :
<?php
return function($page) {
// fetch pages
$articles = page('blog')->children()->listed()->flip();
// fetch tags
$tags = $articles->pluck('tags', ',', true);
sort($tags);
// add tag filter
if($tag = urldecode(param('tag'))) {
$articles = $articles->filterBy('tags', $tag, ',');
}
// apply pagination
$articles = $articles->paginate(12);
$pagination = $articles->pagination();
return compact('articles', 'tags', 'tag', 'pagination');
};
What am I missing ?
Thank you for your help.