-
-
Save isellsoap/4319585 to your computer and use it in GitHub Desktop.
Kirby: yearly archive of blog articles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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