杰基尔的类别页面 [英] Category Page in Jekyll
问题描述
我有一个category.html
页面,该页面将循环浏览某些类别的帖子.
I have a category.html
page that will loop through a certain category of posts.
{% for post in site.categories.tech %}
当用户单击
{{ post.categories }}
这是通过显示所有帖子的循环生成的.
Which is generated from a loop that displays all of the posts.
{% for post in site.posts %}
我需要该{{ post.categories }}
变量来替换categories.html
中的.tech
I need that {{ post.categories }}
variable to replace the .tech
in the categories.html
like this
{% for category in site.categories.{{ post.categories }} %}
我不知道如何将变量从index.html
传递到categories.html
I don't know how to pass the variable from index.html
to categories.html
推荐答案
站点类别是一个对象,其中每个键都是类别名称.所以
Site categories is an object where each key is the category name. So
{{ site.categories }}
输出如下内容:
{
"Category name" => [#, #, #, #, #, #, #],
"Another category name" => [#, #, #, #, #, #, #],
...
}
因此,方括号应该这样做.因此,如果您将index.html放在首位,那么
Therefore, square brackets should do it. So if in the front matter of your index.html you have
---
categories: tech
---
下面的代码将呈现您所有属于技术类别的帖子.
The code below will render all your posts under tech category.
{% for post in site.categories[post.categories] %}
{{ post }}
{% endfor %}
如果您在前面有多个类别,那么这当然行不通,但是我不知道您的用例.
Of course this won't work if you have multiple categories in the front matter, but I don't know your use case.
这篇关于杰基尔的类别页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!