This seems to be pretty simple but I am still in a struggle with code. Because most of the tag discussions here in the forums deal with the tag cloud - this is not my question.
I have a site with different pages, all of them built like a blog (and in fact using the method for blogs that is described in the Kirby documentation), and all of them using a blog.php template. Each article (blogarticle.php) has a set of tags. What I want to achieve is a result page that shows me all the articles that I marked with a certain tag as soon as I click on that tag on the article page.
Example:
(page) Projects > (article) Hygiene > (tags) Women, Customs, Population
(page) Events > (article) Conference > (tags) Health, Asia, Women
(page) Publications > (article) Childrenâs care > (tags) Asia, Population, Education
When I click on the tag âAsiaâ I would want a list showing
- Conference
- Childrenâs care
Since my use of PHP is more based on logic thinking (uf, thanks god it helps in most cases) rather than on profound knowledge I would appreciate some help, unless it causes too much work and attention.
I tried to start with a controller for blogarticle.php
<?php return function($site, $pages, $page) {
// fetch the basic set of pages
$articles = $page('???????')->children()->visible()->flip();
// add the tag filter
if($tag = param('tag')) {
$articles = $articles->filterBy('tags', $tag, ',');
}
// ??????
// apply pagination
$articles = $articles->paginate(10);
$pagination = $articles->pagination();
}; ?>
And this is the idea for the blogarticle.php template:
<ul class="tag menu">
<?php foreach($page->tags()->split(',') as $tag): ?>
<li><a <?php ecco($tag == urlencode(param('tag')), ' class="active"') ?> href="<?php echo url('link to page one level up' . $tag - here one level down again)?>"><?php echo $tag ?></a></li>
<?php endforeach ?>
</ul>