Hi,
I created 2 different filters in my controller for my products page.
<?php
return function($site, $pages, $page) {
$perpage = $page->perpage()->int();
$articles = $page->children()->visible()->flip();
$allarticles = $pages->findByURI('products')->children()->visible()->flip();
if($tag = param('tag')) {
$articles = $articles->filterBy('tags', $tag, ',');
}
if($subtag = param('subtag')) {
$articles = $articles->filterBy('subtags', $subtag, ',');
}
$tags = $articles->pluck('tags', ',', true);
$alltags = $allarticles->pluck('tags', ',', true);
$subtags = $articles->pluck('subtags', ',', true);
$allsubtags = $allarticles->pluck('subtags', ',', true);
$articles = $articles->paginate(($perpage >= 1)? $perpage : 5);
$pagination = $articles->pagination();
return compact('articles', 'tags', 'alltags', 'tag', 'subtags', 'allsubtags', 'subtag', 'pagination');
};
In my products page there are two loops with all the tags and the subtags
<?php $p = kirby()->request()->params()->tag(); ?>
<?php foreach($alltags as $tag): ?>
<li class="<?php ecco($tag == $p, 'active-tag') ?> ">
<a href="<?php echo url($page->url() . '/' . url::paramsToString(['tag' => $tag])) ?>">
<?php echo html($tag) ?>
</a>
</li>
<?php endforeach ?>
<?php $p = kirby()->request()->params()->subtag(); ?>
<?php foreach($allsubtags as $subtag): ?>
<li class="<?php ecco($subtag == $p, 'active-tag') ?> ">
<a href="<?php echo url($page->url() . '/' . url::paramsToString(['subtag' => $subtag])) ?>">
<?php echo html($subtag) ?>
</a>
</li>
<?php endforeach ?>
Everything works perfectly, but I can filter only one element at a time. My dream is to filter one element from the tag (first filter) and one element from the subtag (second filter) at the same time (show the the sum of the two filters).
Is it possible?
Can you help me?