Hi all,
Struggling with this one, currently only showing articles on the tag results page but not the projects… have gone over the code and can’t seem to find the correct combination.
I have project pages and post pages which show the tags and category near the footer. What I’m hoping to achieve is when the users clicks on the tag, or category it directs to a results page listing everything with the same tag or category.
Thanking you in advanced for your help!
Results.php Controller:
<?php
return function($site, $pages, $page) {
// fetch the basic set of pages
$articles = $site->index()->filterBy('template', 'writing', 'project');
// add the tag filter
if($tag = param('tag')) {
$articles = $articles->filterBy('tags', $tag, ',');
}
// fetch all tags
$tags = $articles->pluck('tags', ',', false);
// apply pagination
$articles = $articles->paginate(10);
$pagination = $articles->pagination();
return compact('articles', 'tags', 'tag', 'pagination');
}
results php page:
<?php snippet('header') ?>
<main class="main" role="main">
<ul>
<?php foreach($articles as $articles): ?>
<li>
<a href="<?= $articles->url() ?>">
<?= $articles->title()->html() ?>
</a>
</li>
<?php endforeach ?>
</ul>
</main> <?php snippet('footer') ?>