在jekyll markdown中的IF逻辑

时间:2017-02-15 20:15:19

标签: markdown jekyll blogs

在我的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,但它没有效果

1 个答案:

答案 0 :(得分:1)

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

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

过滤帖子

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