Skip to content

Instantly share code, notes, and snippets.

@agarie
Created August 3, 2012 04:44
Show Gist options
  • Save agarie/3244468 to your computer and use it in GitHub Desktop.
Save agarie/3244468 to your computer and use it in GitHub Desktop.
Creating a list of posts separated by year and month with liquid templating
<ul class="post-list unstyled">
{% for post in site.posts %}
{% capture post_year %}
{{ post.date | date: "%Y" }}
{% endcapture %}
{% unless year == post_year %}
{% assign year = post_year %}
<h1>{{ year }}</h1>
{% endunless %}
{% capture post_month %}
{{ post.date | date: "%B" }}
{% endcapture %}
{% unless month == post_month %}
{% assign month = post_month %}
<h2>{{ month }}</h2>
{% endunless %}
<li>
<a href="{{ post.url }}"><span class='important'>{{ post.date | date: "%d" }}</span> {{ post.title }}</a>
</li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment