Skrivr – The original Dropbox powered writing app. Write, save, published!    Request an invite »
News – Tuesday, 28 May, 2013

Display 5 most recent posts from a category

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:

5 most recent news items on 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>
    {% for post in post_feed|slice(0,5) if post.category == 'Categoryname' %}
        <li><a href="{{ post.permalink }}">{{ post.headline }}</a></li>
    {% endfor %}
<a href="/categoryname">See all »</a>
More from Skrivr