jekyll 降价中的 IF 逻辑

IF logic in jekyll markdown

在我的 jekyll 博客上已经有一个页面列出了所有类别及其各自的帖子,这是代码:

{% for category in site.categories %}
<div class="col-md-12 content-panel articles">
  <h2 id="{{ category | first }}-ref">{{ category | first }}</h2>
  <ul style="list-style: none;">
    {% for posts in category %}
      {% for post in posts %}
        <li>
          <!-- problem of for cycle can't use images <img src="/{{ post.header-img | prepend: site.baseurl }}" class="img-responsive" alt="{{ post.title }}"> -->
          <h3><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a></h3>
          <small class="hidden-xs">{{ post.date | date: "%B %-d, %Y" }}</small>
        </li>
      {% endfor %}
    {% endfor %}

  </ul>
</div>
{% endfor %}

我的问题是,如何才能只显示 categoryX 上的帖子?

我意识到这可能很简单,但找不到任何方法,我尝试将 for posts in category 更改为 for posts in categoryX 但它没有用

要列出特定类别,您可以使用 site.categories.CATEGORY 指定它,以便它列出类别 CATEGORY 中的所有帖子。

例如,如果您有一个名为 "diet" 的类别,您可以使用 {% assign posts = site.categories.diet %}{% for post in posts %}.. 或 {% assign posts = site.category['diet'] %}

过滤其帖子

在这里查看一些 Jekyll 变量:https://jekyllrb.com/docs/variables/