首页 > 解决方案 > 在 Jekyll 博客中显示当前类别的帖子

问题描述

我想在 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 }}。侧边栏显示了我

阿巴卡德

什么是问题,我该如何解决?

标签: jekyllliquid

解决方案


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


推荐阅读