2013-09-24 17 views
2
<section id="article"> 
    <h3>Recent posts</h3> 
<ul> 
    {% for post in site.posts %} 
     <li>&raquo; <a href="{{ post.url }}">{{ post.title }}</a></li> 
    {% endfor %} 
    </ul> 
</section> 

這是我所有文章的代碼,我如何控制帖子數量,並在該部分顯示10個帖子?如何控制我最近發佈的Jekyll?

回答

8

這是做到這一點的方法。

{% for post in site.posts offset: 0 limit: 10 %} 
+0

嗨,你知道爲什麼我的這篇文章的網址包含'%5c',無法正確打開。 [錯誤的網址](http://hypergroups.github.io/mathematica%5Cmath-experiment/2013/09/11/Math_Experiment-Limit),您可以從我的主頁打開它,並且html文件是[here]( https://github.com/HyperGroups/hypergroups.github.com/blob/master/_posts/Mathematica/Math-Experiment/2013-09-11-Math_Experiment-Limit.html)。 – user92733

1
<section id="article"> 
    <h3>Recent posts</h3> 
    <ul> 
    {% for post in site.posts limit:10 %} 
     <li><a href="{{ post.url }}"> 
    {% endfor %} 
    </ul> 
</section> 

試試這一個。此代碼顯示10個最近發佈的帖子,如最近發佈的帖子。

0

我會用另一種方式去談論它。

{% for post in site.posts limit:1 %} 
{% if forloop.last %} 
    <li> 
    <a href="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a> 
    </li> 
{% endif %} 
{% endfor %} 

我已經包含了一個if邏輯標籤與forloop.last所以它只會顯示最後一個,最近的帖子。由於我還包含{limit:1},所以輸出結果只會是一個帖子。