2016-08-18 88 views
1

我有以下液體代碼來顯示每個類別下的帖子的類別列表和標題列表。如何在jekyll中刪除empy帖子

{% for category in site.categories %} 
<a name="{{ category | first }}">{{ category | first }}</a> 
<ul> 
{% for posts in category %} 
    {% for post in posts %} 
     <li><a href="{{ post.url }}">a{{ post.title }}a</a></li> 
    {% endfor %} 
{% endfor %} 
</ul> 
{% endfor %} 

這顯示職位列表作爲附加的圖像 output of the above Liquid code

正如你可以在PIC看到有兩類「降價」和「溫度」。列出每個職位的職位名稱。但是,這裏每個類別中的第一個列表項顯示爲空。你能告訴我如何擺脫這個空白列表項目並顯示其他所有內容,如圖片所示。

回答

0

您可以檢查標題的長度:

{% for category in site.categories %} 
<a name="{{ category | first }}">{{ category | first }}</a> 
<ul> 
{% for posts in category %} 
    {% for post in posts %} 

     {% assign title_length=post.title | size %} 
     {% if title_length > 0 %} 

     <li><a href="{{ post.url }}">a{{ post.title }}a</a></li> 

     {% endif %} 

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