Created
August 3, 2012 04:44
-
-
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
This file contains 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
<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