2014-04-18 39 views
2

中有幾個條件(類別,語言,標籤)的帖子的帖子索引我想在我的Jekyll網站上爲幾個類別語言提供幾個後索引(索引?),這意味着多於一個條件。在Jekyll

我的帖子有YAML frontmatter包括:

categories: 
    - research 
    - blog 
lang: en 

現在,我想一個帖子指數,因爲,用英語說所有的研究文章。

我可以這樣做:

{% for post in site.posts %} 
    {% if post.lang == 'en' and post.categories contains 'research' %} 
     {{ post.title }} 
    {% endif %} 
{% endfor %} 

然而,這螺絲了這樣細微的限制和按年份等。限位柱(等)的數量,哲基爾似乎仍然看帖子整個名單,不只是對他們來說,有條件的適用。

事情是這樣的僞代碼將是理想的: {%爲崗位在post.lang == '恩' 和post.categories site.posts包含 '研究' %}

有什麼想法?

詩:我不能使用任何插件;希望它是GH頁面兼容。 PPS:我知道我可以用語言作爲一個類別,但感覺不對 - 這是不同的信息。

回答

2

我相信你可以這樣做:

{% assign resindex = site.posts | where: "category", "research", | where: "lang", "en" | sort: "title" %} 
{% for post in resindex limit:4 %} 
<div> 
<p><a href="{{ post.url }}">{{ post.title | truncate: 52 }}</a></p> 
    </div> 
{% endfor %} 

雖然我還算通過使用類別和類別以及何時可以/應該使用他們的困惑。在我的例子類的工作,但在我的前面的問題,我有:類別:mycategory,而且只使用一個。但其他代碼應該可以工作,並且可以限制和排序。