从集合中获取jekyll子类别帖子

时间:2018-02-21 11:09:20

标签: jekyll config blogs posts

我的收藏帖子有一个子类别,但我有循环问题,我只需要一个特定的子类别。

config.yml

collections:
  news:
    output: true
  cat1:
    output: true
    permalink: /news/cat1/:title/
  cat2:
    output: true
    permalink: /news/cat2/:title/
  cat3:
    output: true
    permalink: /news/cat3/:title/
  cat4:
    output: true
    permalink: /news/cat4/:title/

这是html文件

---
# this is an empty front matter
title: 'Cat 1 news'
permalink: /news/cat1/
---

{% for item in site.news %}
  {% for post in item.cat1 %}
    {{ post.title }}<br>
  {% endfor %}
{% endfor %}

这是

的目录树
_news
|  cat1
|  cat2
|  cat3
|  cat4

1 个答案:

答案 0 :(得分:0)

您可以使用:

{% for post in site.cat1 %}

{% assign myCategory = "cat1" %}
{% for post in site[mycategory] %}