templatesjekylltemplatingliquidliquid-layout

How can I show just the most recent post on my home page with jekyll?


<ul class="entries">
  {% for post in paginator.posts %}
  <li>
    <a href="{{ post.url }}">
    <h3>{{ post.title }}</h3>
    <p class="blogdate">{{ post.date | date: "%d %B %Y" }}</p>
    <div>{{ post.content |truncatehtml | truncatewords: 60 }}</div>
    </a>
  </li>
  {% endfor %}
</ul>

That shows all my posts, I just want to show the most recent.


Solution

  • This can be accomplished through the use of limit:

    {% for post in site.posts limit:1 %}
    ... Show the post ...
    {% endfor %}
    

    You can also use limit and offset together to "feature" your most recent post:

    <h1>Latest Post</h1>
    {% for post in site.posts limit:1 %}
    ... Show the first post all big ...
    {% endfor %}
    <h1>Recent Posts</h1>
    {% for post in site.posts offset:1 limit:2 %}
    ... Show the next two posts ...
    {% endfor %}