【发布时间】:2011-06-14 03:17:57
【问题描述】:
我有一个jekyll 网站和一个类别(称为photo),我想为一个仅列出photo 类别中的帖子的页面创建一个单独的布局。我还想将 photo 类别的帖子保留在主索引页面之外。
【问题讨论】:
我有一个jekyll 网站和一个类别(称为photo),我想为一个仅列出photo 类别中的帖子的页面创建一个单独的布局。我还想将 photo 类别的帖子保留在主索引页面之外。
【问题讨论】:
站点对象中的所有类别都可用,通过site.categories.photo 访问某个类别的帖子,这样您的循环将如下所示
{% for post in site.categories.photo %}
# render the photo post html
{% endfor %}
【讨论】:
photo 帖子
我只是在主索引页面中使用了{% unless %} 块来确保帖子不是照片。示例:
{% unless post.category == "photo"%}
{% comment %} List posts... {% endcomment %}
{% endunless %}
我用同样的方法只显示张照片。只需使用 if 而不是 unless。
【讨论】:
unless 标签上找不到任何信息。还支持吗?
类别也区分大小写。如果您的类别是照片,那么它将如下所示:
{% for post in site.categories.photo %}
# render the photo post html
{% endfor %}
如果您的类别是照片,那么它将如下所示:
{% for post in site.categories.Photo %}
# render the photo post html
{% endfor %}
只是我在构建过程中遇到的一个快速细节,所以我想我会分享。
【讨论】: