Skip to content

Instantly share code, notes, and snippets.

@floriandotpy
Created November 5, 2015 16:39
Show Gist options
  • Save floriandotpy/706a365282f49cb1ad44 to your computer and use it in GitHub Desktop.
Save floriandotpy/706a365282f49cb1ad44 to your computer and use it in GitHub Desktop.
title : Home
layout: blog/index
===
<!-- Find blog folders 2010, 2011, ... -->
<?php $years = $page->children()->filter(function($p) { return preg_match("/^\d{4}$/", $p->slug()); }); ?>
<!-- Go through all blog folders, collect articles in one single array -->
<?php $allarticles = []; ?>
<?php foreach ($years as $year): ?>
<?php foreach ($year->children() as $article): ?>
<?php $allarticles[] = $article; ?>
<?php endforeach; ?>
<?php endforeach; ?>
<!-- Turn back into PageCollection and sort by date -->
{% $page->set('articles', (new COCOPi\Lib\PageCollection($allarticles))->visible()->sort('$p->meta("date")', 'desc')) %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment