向Jekyll中的帖子添加类

向Jekyll中的帖子添加类,jekyll,Jekyll,我有下面的杰基尔索引 --- layout: default title: My favourite sandwiches --- <section class="home"> {% for post in site.posts %} <article class="column"> <img src="{{ post.image }}"> <a href="{{ post.url }}">{{ post.ti

我有下面的杰基尔索引

---
layout: default
title: My favourite sandwiches
---

<section class="home">
  {% for post in site.posts %}
    <article class="column">
      <img src="{{ post.image }}">
      <a href="{{ post.url }}">{{ post.title }}</a>
    </article>
  {% endfor %}
</section>

感谢您的耐心和时间。

液体for loop有可用的辅助变量,如
forloop.first
forloop.last
。见文件

在你的情况下,我会尝试:

---
layout: default
title: My favourite sandwiches
---

<section class="home">
  {% for post in site.posts %}

    {% if forloop.first %}
      <article class="column first">
    {% elsif forloop.last %}
      <article class="column last">
    {% else %}  
      <article class="column">
    {% endif %}

      <img src="{{ post.image }}">
      <a href="{{ post.url }}">{{ post.title }}</a>
    </article>
  {% endfor %}
</section>
---
布局:默认值
标题:我最喜欢的三明治
---
{site.posts%中的post为%s}
{%if-forloop.first%}
{%endfor%}

首先,谢谢。第二,感谢您对文档的简明解释和归属!“我欠你一个三明治。”瓦萨比德维勒:很高兴它有用。是的,我想要一个大三明治,循环中的第一个。英雄联盟
---
layout: default
title: My favourite sandwiches
---

<section class="home">
  {% for post in site.posts %}

    {% if forloop.first %}
      <article class="column first">
    {% elsif forloop.last %}
      <article class="column last">
    {% else %}  
      <article class="column">
    {% endif %}

      <img src="{{ post.image }}">
      <a href="{{ post.url }}">{{ post.title }}</a>
    </article>
  {% endfor %}
</section>