2011-06-11 67 views
0

我使用液體(https://github.com/tobi/liquid/)在我的模板中呈現內容。 我想在我的主頁上有一個「最近的活動」部分,它將查找按日期排序的三種不同內容類型的最新更新,限制爲四個。將內容類型與液體模板語言結合使用

這是可能的液體?

所以,用通俗易懂的語言查詢會是這樣的.. 「選擇由CONTENT_TYPE_1,2或3日期排列的四個最新項目」

感謝, 馬克。

回答

1

按content_type,我假設你是指帖子的類別。您可以通過添加

category: type_1 

到您的文章的YAML Front Matter或把該職位在type_1/_posts文件夾分類您的帖子。 一旦我們有這個,這是一個稍微俗氣的做你想做的事情:

<div> 
    {% assign count1 = true %} 
    {% assign count2 = true %} 
    {% assign count3 = true %} 
    {% assign count4 = true %} 
    {% for post in site.posts %} 
    {% if post.categories contains 'type_1' or post.categories contains 'type_2' or ... %} 
     {% if count1 == true or count2 == true or count3 == true or count4 == true %} 
      <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li> 
      {% if count1 == true %} 
       {% assign count1 = false %} 
      {% elsif count2 == true %} 
       {% assign count2 = false %} 
      {% elsif count3 == true %} 
       {% assign count3 = false %} 
      {% elsif count4 == true %} 
       {% assign count4 = false %} 
      {% endif %} 
     {% endif %} 
    {% endif %} 
    {% endfor %} 
</div>