【问题标题】:Display posts of current category in Jekyll blog在 Jekyll 博客中显示当前类别的帖子
【发布时间】:2021-06-25 06:13:12
【问题描述】:

我想在 Jekyll 博客中显示当前类别的帖子。所以,我写了如下代码。

<div class="side-left col-sm-4 col-md-4">
  {% for category in site.categories %}
    {% if page.categories == category.first %}
    <h3 class="lead"> {{ category | first }} </h3><hr>
    <ul>
      {% for post in category[1] limits:5 %}
      <li><a href="{{ post.url }}" style="color:whitesmoke;"> {{ post.title | truncate:40 }}</a></li>
      {% endfor %}
    </ul>
    {% endif %}
  {% endfor %}
</div>

但是当我更新博客时,侧边栏没有任何反应。为了考试,我在第 2 行和第 3 行之间写了 {{ page.categories }} {{ category.first }}。侧边栏显示了我

A A A B A C A D

什么是问题以及如何解决?

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    {{ category }} 是一个字符串而不是一个数组,所以当你写 {{ category.first }} 时,你会得到字符串的第一个字母;)。

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 2014-01-19
      • 2018-07-09
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      相关资源
      最近更新 更多