Jekyll index of posts

Thank you Kevin for the videos and the site! You have been super helpful to me. I have been setting up my blog following your videos and am setting up to display and index of posts on the homepage. However I was wondering if you knew of a way to display only the newest posts, say 5 or 6 posts?

<ul>
  {% for post in site.posts %}
    {% if forloop.index <= 5 %}
      <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
      </li>
    {% else %}

    {% endif %}
  {% endfor %}
</ul>

This is where I have gotten to but it only shows three posts even when I change the 5 to 10. If I change the 5 to 2 then it shows 2 posts.
1 Like

Pretty sure you’re looking for the limit keyword:

{% for post in site.posts limit 6 %}

Answered my own question as I was going to make dinner. I had the names of two of my test posts as future dates and they would not showed up. Changed the dates to 2021 for the test and it worked great. Decided not to delete it in case someone else questions this.

Ah nice! I think the limit keyword might make your life a little easier, but I’m glad you got it sorted out!

That does sound much easier. Thank you!

1 Like