I want to move my WordPress site to Kirby and I am testing Kirby to learn how it works. So far, I like it
I have some problems to get the tag-filters working. I have tried the cookbooks https://getkirby.com/docs/cookbook/content/filtering-with-tags.
And read some forum post (e.g. #1, #2) last few days, but I can’t figure out, what I am doing wrong.
So, some help and tipp are welcome
My YAML-File for one of the tags
fields:
b17generalFilters:
label: General Filters
type: tags
options: query
query: page.siblings.pluck('b17generalFilters', ',', true)
translate: false
The parent page slug is “b17”, which shows all the articles and template named “b17.php”.
<?php foreach( $articles as $article): ?>
<article class="col-12 col-xxl-4">
<?php if($image = $article->b17cover()->toFile()): ?>
<a href="<?= $article->url() ?>"><img src="<?= $image->thumb(['format' => 'webp'])->url() ?>" alt="<?= $article->title() ?>" class="img-fluid"></a>
<?php endif ?>
<h2><?= $article->title()->html() ?></h2>
<a href="<?= $article->url() ?>">Read more…</a>
</article>
<?php endforeach ?>
Controller in site/controllers/b17.php
return function ($page) {
$b17entries = $page->children()->listed()->flip();
$generalfilters = $b17entries->pluck('b17generalFilters', ',', true);
// add the tag filter
if($generalfilter = param('b17generalFilter')) {
$articles = $b17entries->filterBy('b17generalFilters', $generalfilter, ',');
}
// apply pagination
$articles = $b17entries->paginate(3);
$pagination = $articles->pagination();
return compact('articles', 'generalfilters', 'generalfilter', 'pagination');
};
The article template to show a single article, which created as child pages named “b17entry.php”. The values of the “b17generalFilter” are shown correctly.
This is the part of the code in "b17entry.php"
<h3>General Filters</h3>
<ul>
<?php foreach ($page->b17generalFilters()->split() as $filter): ?>
<li><a href="<?= url('b17/b17generalFilters:' , ['params' => ['b17generalFilters' => urlencode($filter)]]) ?>"><?= $filter ?></a></li>
<?php endforeach ?>
</ul>
If I am clicking on the link of the filter. It will shows the parent page “b17” with all the articles. But not filtered with the tag-url, I have clicked.
I am not sure, if the URL is wrong and I have miss-understood some thing. The URL looks like this for the Filter value “B-17 Green Project”: https://domain.tld/b17/b17generalFilters:B-17+Green+Project
I would be happy if some one can help me
My goal is to create multiple filters (e.g. #1, #2) and then search for articles after filtered.
But for the first step, I need to learn the Kirby basics