如何从Jekyll的相关帖子中排除当前帖子?

我的代码是:

<div class="recent-posts">

  {% for post in site.posts |  limit:3 %}

  <div class="recent-posts-inline">

      {% if post.featured-image %}{% include post-featured-image.html image=post.featured-image alt=page.featured-image-alt %}{% endif %}

    <h4>
      <a href="{{ post.url }}">{{ post.title }}</a>
    </h4>

    <p>{{ post.excerpt | strip_html | strip_newlines | truncate: 156 }}</p>
    <p><a href="{{ post.url }}">Read More...</a></p>
  </div>

  {% endfor %}
</div>

我尝试使用where_exp过滤器,但无济于事。这就是为什么我不得不再次问这个问题。

jia654112637 回答:如何从Jekyll的相关帖子中排除当前帖子?

在if-check中使用page variable。仅当帖子与当前页面标题不同时才执行某些操作。如果要进行其他比较,可以检查.url.id.name

<div class="recent-posts">

  {% for post in site.posts |  limit:3 %}
    {% if post.title != page.title %}

      <div class="recent-posts-inline">
      ...

    {% endif %}
  {% endfor %}
</div>
本文链接:https://www.f2er.com/3089452.html

大家都在问