Skip to content

Instantly share code, notes, and snippets.

Created April 6, 2012 00:24
Show Gist options
  • Save anonymous/2315384 to your computer and use it in GitHub Desktop.
Save anonymous/2315384 to your computer and use it in GitHub Desktop.
how to filter by tag params?
<?php snippet('header') ?>
<?php snippet('menu') ?>
<?php
/* WHRE DO I PUT THE FOLLOWING CODE SO THAT /blog/tag:SomeTagName works?
When I click on a tag link, it still displays all the articles even if the tags don't match.
*/
if(param('tag')) {
$article = $pages->find('blog')
->children()
->visible()
->filterBy('tags', param('tag'), ',')
->flip()
->paginate(10);
} else {
$article = $pages->find('blog')
->children()
->visible()
->flip()
->paginate(10);
}
?>
<section class="content blog">
<h1><?php echo html($page->title()) ?></h1>
<?php echo kirbytext($page->text()) ?>
<!-- FOR EACH LOOP BEGIN -->
<?php foreach($page->children()->visible()->flip() as $article): ?>
<article>
<h1><?php echo html($article->title()) ?></h1>
<p><?php echo excerpt($article->text(), 300) ?></p>
<a href="<?php echo $article->url() ?>">Read more…</a>
<?php echo $article->tags() ?>
</article>
<?php endforeach ?>
<!-- FOR EACH LOOP END -->
<hr/>
<hr/>
<!-- CLICKABLE TAG CLOUD GENERATOR -->
<?php $tagcloud = tagcloud($pages->find('blog'), array('limit' => 20)) ?>
<ul>
<?php foreach($tagcloud as $tag): ?>
<li><a href="<?php echo $tag->url() ?>"><?php echo $tag->name() ?></a></li>
<?php endforeach ?>
</ul>
<hr/>
</section>
<?php snippet('footer') ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment