Hi, i’ve been trying to implement tags and tagcloud for a ‘review’ blog - apologies as this seems to be a common question, but i’ve looked through the forums and haven’t been able to get any of the suggestions to work.
First off, i’ve been able to get each individual ‘review’ page to work as intended:
I have a ‘results’ sub page, and the following controller for results.php:
<?php return function($site, $pages, $page) {
// fetch the basic set of pages
$reviews = $site->index()->filterBy('template', 'review');;
// add the tag filter
if($tag = param('tag')) {
$reviews = $reviews->filterBy('tags', $tag, ',');
}
return compact('reviews');
};
And then on each ‘review’ page the tags are called like this:
<?php foreach($page->tags()->split(',') as $tag): ?>
<ul class="tags">
<li><a <?php ecco($tag == urlencode(param('tag')), ' class="active"') ?> href="<?php echo url('results/tag:' . $tag)?>"><?php echo $tag ?></a></li>
</ul>
<?php endforeach ?>
What i’m now trying to do is include a tagcloud on a seperate ‘filter’ sub page, that lists all of the tags used in every ‘review’ page, and have these tags take you to the same ‘results’ page.
So my site structure is:
01.Reviews
- (review) example 1 – tags: one, two, three
- (review) example 2 – tags: three, four, five
02.Filter
home
results
I have the tagcloud plugin, and I can get the list of tags to work on the ‘filter’ page with the following:
<ul><?php $tagcloud = tagcloud(page('reviews'), array()) ?>
<?php foreach($tagcloud as $tag): ?>
<li><a href="<?php echo $tag->url() ?>"><?php echo $tag->name() ?></a></li>
<?php endforeach ?>
</ul>
However these tags just take you to the main ‘reviews’ page, not the ‘results’ page. Is there anyway of changing where these tags link to from the ‘filter’ sub page? Or any other way of controlling where these tags take you?
Cheers.