【发布时间】:2014-10-31 05:48:59
【问题描述】:
所以基本上我有this problem。我想将类别名称打印为标题,但是到目前为止,我尝试过的任何内容都无法使用包含多个单词的类别,因此我已经解决了在每个帖子中设置标签和类别的问题。
所以在做出这个决定后,我测试了 2 个标签和 2 个类别,tag1 用于 cat1 和 tag2 用于 cat2,其中每个标签都有一个对应的类别。然后我将这些标签/猫对添加到我的一些帖子中。我的算法是这样的:
for loop in tags
print category in a heading tag
for loop in posts of that category
print some post info
翻译成代码如下:
{% assign i = 0 %}
{% for TAG in site.tags %}
<p>Checking the i: {{ i }}</p>
<p>Checking the tag: {{ TAG }}</p>
<h1>Checking the cat: {{ site.categories[i] }}</h1>
{% for post in site.tags.TAG %}
<p>{{ post.title }}</p>
{% endfor %}
{% assign i = i + 1 %}
{% endfor %}
输出是:
Checking the i: 0
Checking the tag: tag1
THE WHOLE POST
Checking the cat: (nothing is printed here)
Checking the i: 0
Checking the tag: 0
Checking the cat: (nothing is printed here)
然后它就停止了。
所以我的问题是:
- 如何访问类别?现在它什么也没打印
- 为什么在标签后打印整个帖子内容?
- 为什么只打印一个标签?
- 为什么
i在循环结束时不递增?
【问题讨论】: