首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Jekyll的相关帖子中排除当前帖子?

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

Stack Overflow用户
提问于 2019-11-17 00:31:24
回答 1查看 57关注 0票数 0

我的代码是:

代码语言:javascript
复制
<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过滤器,但没有用。这就是为什么我要再问这个问题的原因。

EN

回答 1

Stack Overflow用户

发布于 2019-11-17 03:30:38

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

代码语言:javascript
复制
<div class="recent-posts">

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

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

    {% endif %}
  {% endfor %}
</div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58892833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档