Tuesday, 28 May, 2013
Display 5 most recent posts from a category
A very useful thing when having a lot of posts is to only list the most recent. This is what we have done on the main page of the Skrivr Blog:
Here is the code for displaying the 5 most recent. If you change the number in post_feed|slice(0,5)
you will change how many posts that is displayed.
<a href="/categoryname">Categoryname</a>
<ul>
{% for post in post_feed|slice(0,5) if post.category == 'Categoryname' %}
<li><a href="{{ post.permalink }}">{{ post.headline }}</a></li>
{% endfor %}
</ul>
<a href="/categoryname">See all »</a>