【问题标题】:Jekyll, show category for a single postJekyll,显示单个帖子的类别
【发布时间】:2015-03-09 15:18:43
【问题描述】:

使用 Jekyll - 我想显示给定帖子所属的类别列表。

在我的 post.html 布局中,我有以下代码块,它呈现了网站的所有类别。

<p>Posted in: 
  {% for category in site.categories %}
    <a href="/blog/{{ category | first | slugize }}/">
      {{ category | first }}
    </a>
  {% endfor %}
</p>

我想展示的是这篇文章所在类别的列表。我尝试用 page.categories 和 post.categories 替换 site.categories,但无济于事。

任何帮助将不胜感激。

【问题讨论】:

    标签: jekyll categories liquid


    【解决方案1】:

    不要使用site.categories,而是使用page.categories。此外,您不需要first-filter,因为您已经遍历了数组:

    {% for category in page.categories %}
      <a href="/blog/{{ category | slugize }}/">
        {{ category }}
      </a>
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 2018-07-09
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 2014-01-03
      • 2017-07-28
      • 1970-01-01
      相关资源
      最近更新 更多