Skip to content

Instantly share code, notes, and snippets.

@isellsoap
Forked from anonymous/Kirby Archive
Created December 17, 2012 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isellsoap/4319585 to your computer and use it in GitHub Desktop.
Save isellsoap/4319585 to your computer and use it in GitHub Desktop.
Kirby: yearly archive of blog articles.
<?php
$blog_uri = 'blog';
$articles = $pages->find( $blog_uri )->children()->visible()->sortBy( $sort='date', $dir='desc' );
$year = date( 'Y' );
?>
<ul>
<?php
// loop through blog articles
foreach ( $articles as $article ) {
// print year
if ( $article->date( 'Y' ) <= $year ) {
$year = $article->date( 'Y' );
echo '<li>' . $year . '<ul>';
$year--;
}
// print blog article
echo '<li>' . $article->date( 'M d' ) . ': <a href="' . $article->url() . '">' . html( $article->title() ) . '</a></li>';
// close the list if first article of the year is reached
if ( $article->hasPrev() && $article->date( 'Y' ) > $article->prev()->date( 'Y' ) ) {
echo '</ul></li>';
}
}
?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment