我是新来的杰基尔。我知道Jekyll用下面的代码支持显示最近的帖子:
<div id="recent-posts" class="recent-posts">
{% for this_post in paginator.posts %}
<div class="post">
<a href="{{ this_post.url }}">
<h2 class="post-title">{{ this_post.title }}</h2>
</a>
{% include category_info %}
{% include source_info %}
</div>
{% endfor %}
</div>但我不想显示帖子的类别,因为类别名称是"notshowing"。我怎么才能做到呢?
发布于 2017-03-08 03:46:56
要避免显示特定类别,可以使用unless筛选器:
只有在不满足特定条件时(即,如果结果为假),
才会执行一段代码。
例如,在for循环中使用{% unless post.categories contains "notshowing"%}
在您的示例中,使用站点posts site.posts而不是paginator.posts (您可以根据需要进行调整),如下所示:
<div id="recent-posts" class="recent-posts">
{% for post in site.posts %}
{% unless post.categories contains "notshowing"%}
<div class="post">
<a href="{{ post.url }}">
<h2 class="post-title">{{ post.title }}</h2>
</a>
</div>
{% endunless %}
{% endfor %}
</div>https://stackoverflow.com/questions/42656672
复制相似问题