将jekyll帖子列表限制为某些类别

Mar*_*ski 21 liquid jekyll

我有一个jekyll网站,我有一个类别(称为photo),我想为一个页面创建一个单独的布局,只列出该photo类别中的帖子.我还想保留photo主索引页面中的类别的帖子.

Dav*_*ows 34

所有类别都在站点对象中可用,访问类别的帖子,site.categories.photo因此您的循环将如下所示

{% for post in site.categories.photo %}
    # render the photo post html
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

  • @ matb33不是完整的答案,因为他的主索引页面仍然会有`photo`帖子 (2认同)

Mar*_*ski 22

我只是{% unless %}在主索引页面中使用了一个块来确保帖子不是照片.例:

{% unless post.category == "photo"%}
    {% comment %} List posts... {% endcomment %}
{% endunless %}
Run Code Online (Sandbox Code Playgroud)

我用同样的东西显示照片.只是用if而不是unless.