In Jekyll, I would like my homepage to display the most recent posts, grouped by date, for example:
September 6, 2013
- Message 1
- Message 2
- Message 3
September 5, 2013
Basically, I just want to spit out the date header when the post in the loop will be different from the date previously processed. I tried to do this by checking if the next entry in the for loop matches the date of the last message and displays the date header only if it is not. This is what my liquid pattern looks like:
--- layout: default title: Home Page --- {% assign thedate = '' %} {% for post in site.posts %} {% if thedate != post.date | date: "%m-%d-%Y" %} <h2>{{ post.date | date: "%A, %B %e, %Y" }}</h2> {% endif %} {% assign thedate = post.date | date: "%m-%d-%Y" %} <h3 class="headline"><a href="{{ post.url }}">{{ post.title }}</a></h3> {{ post.content }} <hr> {% endfor %}
If instead of using post.date | date: "%m-%d-%Y" post.date | date: "%m-%d-%Y" instead I just say post.date , it works, and the messages are grouped together, but only if the messages have exactly the same date and time (not only on the same day of the month). Therefore, I am adding more specific post.date | date: "%m-%d-%Y" post.date | date: "%m-%d-%Y" .
Any ideas? Thanks so much for our help!
source share