我如何才能在我的主页上显示最近的post与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> 

这显示了我所有的post,我只是想显示最近的。

这可以通过使用limit来完成:

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

您也可以一起使用limitoffset来“function”您最近的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 %} 

而不是创build一个循环,只是分配variables,并继续前进…

 {% assign post = site.posts.first %}