Skip to content

Instantly share code, notes, and snippets.

@andreasnymark
Created June 12, 2013 19:45
Show Gist options
  • Save andreasnymark/5768459 to your computer and use it in GitHub Desktop.
Save andreasnymark/5768459 to your computer and use it in GitHub Desktop.
Blog roll. Show all post by default, to filter by tag and show archive per year. The blog is structured “…/blog/year/post”; hence the […]->children()->children()
<?php
if(param('tag')) {
// all tags are linked “…/weblog/tag:example”
$posts = $page
->children()
->children()
->visible()
->filterBy('tags', urldecode(param('tag')), ',')
->flip();
} else {
// if no tag, list all based on “…/weblog/year/article”
$posts = $page
->children()
->children()
->visible()
->flip();
if($posts->count()==0) {
// if someone happens to go to “…/weblog/year” this is fallback
$posts = $page
->children()
->visible()
->flip();
}
}
?>
<?php if($posts->count()!=0): ?>
<?php foreach($posts AS $p): ?>
<?php endforeach ?>
<?php else: ?>
<p>Dude, I'm not using that tag on anything. Or am I? I might, I'm so confused&hellip;</p>
<?php endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment