2017-02-15 61 views
1

在我的化身博客已經有一個列出所有類別及其各自所有的帖子的網頁,這裏是代碼:IF在傑基爾降價邏輯

{% for category in site.categories %} 
<div class="col-md-12 content-panel articles"> 
    <h2 id="{{ category | first }}-ref">{{ category | first }}</h2> 
    <ul style="list-style: none;"> 
    {% for posts in category %} 
     {% for post in posts %} 
     <li> 
      <!-- problem of for cycle can't use images <img src="/{{ post.header-img | prepend: site.baseurl }}" class="img-responsive" alt="{{ post.title }}"> --> 
      <h3><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a></h3> 
      <small class="hidden-xs">{{ post.date | date: "%B %-d, %Y" }}</small> 
     </li> 
     {% endfor %} 
    {% endfor %} 

    </ul> 
</div> 
{% endfor %} 

我的問題是,我怎麼能只顯示例如categoryX的帖子?

我意識到這可能是簡單的東西,但無法找到任何地方如何,我試圖改變for posts in categoryfor posts in categoryX但它沒有工作

+0

存儲庫網址可以幫助發現問題。 –

回答

1

要列出使用site.categories.CATEGORY所以它列出類別的所有訊息一個特定的類別,你可以指定它類別。

舉例來說,如果你有一個名爲「飲食」的你可以用{% assign posts = site.categories.diet %}{% for post in posts %}過濾其職位類別..或{% assign posts = site.category['diet'] %}

看一些哲基爾變量在這裏:https://jekyllrb.com/docs/variables/

+0

沒有工作,當我嘗試'{%的帖子在site.categories.diet%}它仍然沒有顯示任何東西,即使在我的帖子我用'類別:「飲食」' – leofontes

+1

@leofontes嘗試{%assign posts = site .categories.diet%} {%發佈在帖子中%} ..或{%assign posts = site.category ['diet']%} – marcanuy

+1

工作過,非常感謝。如果可以,請編輯答案,以便顯示未來其他人可能需要的內容(: – leofontes