This post shows how to use jekyll to generate list of all posts in a website. I am using liquid templating engine to generate list of posts here.



PRINT LATEST 3 POSTS EXCLUDING TOP-MOST 2:

To print latest 3 posts excluding top-most 2 posts will require {% for ipost in postlistsortedbydate limit:3 offset:2 %} inside for loop.

CODE:


{% assign postlistsortedbydate = site.posts %}
<p><ul>
  {% for ipost in postlistsortedbydate limit:3 offset:2 %}
    <li>
        <a href="{{ site.baseurl }}{{ ipost.url }}">{{ ipost.title }} - {{ ipost.date | date_to_rfc822 }}</a>
    </li>
  {% endfor %}
</ul></p>

OUTPUT:



PRINT POST INDEX ALONG WITH LATEST 3 POST

To print post index along with latest 3 posts with you’ve to calculate index yourself as {% assign postindex = postindex | plus: 1 %}.

CODE:


{% assign postindex = 0 %}
<p><ul>
  {% for ipost in postlistsortedbydate limit:3 offset:0 %}
    {% assign postindex = postindex | plus: 1 %}
    <li>
        <a href="{{ site.baseurl }}{{ ipost.url }}">{{ postindex }}# {{ ipost.title }}</a>
    </li>
  {% endfor %}
</ul></p>

OUTPUT:



PRINT TOP 3 POST SORTED BY TITLE

To print latest 3 posts sorted by title first you have to sort array of posts by title into another variable as {% assign postlistsortedbytitle = site.posts | sort: 'title' %}.

CODE:


{% assign postlistsortedbytitle = site.posts | sort: 'title' %}
<p><ul>
  {% for ipost in postlistsortedbytitle limit:3 offset:0 %}
    <li>
        <a href="{{ site.baseurl }}{{ ipost.url }}">{{ ipost.title }} - {{ ipost.date | date_to_rfc822 }}</a>
    </li>
  {% endfor %}
</ul></p>

OUTPUT:



PRINT OLDEST 5 POST, OFFSET 1

To print oldest 5 posts offet 1 if we can’t use: {% for ipost in postlistreversed reversed limit:3 offset:1 %} with reversed keyword. Instead you have to generate another list by reversign and assigning first as {% assign postlistreversed = site.posts | reverse %} and then apply limit:3 offset:1 filter on for loop of new variable named postlistreversed

CODE:


{% assign postlistreversed = site.posts | reverse %}
<p><ul>
  {% for ipost in postlistreversed limit:5 offset:1 %}
    <li>
        <a href="{{ site.baseurl }}{{ ipost.url }}">{{ ipost.title }} - {{ ipost.date | date_to_rfc822 }}</a>
    </li>
  {% endfor %}
</ul></p>

OUTPUT: