如何在jekyll中删除empy帖子
问题描述:
我有以下液体代码来显示每个类别下的帖子的类别列表和标题列表。如何在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看到有两类“降价”和“温度”。列出每个职位的职位名称。但是,这里每个类别中的第一个列表项显示为空。你能告诉我如何摆脱这个空白列表项目并显示其他所有内容,如图片所示。
答
您可以检查标题的长度:
{% 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 %}