【问题标题】:Jekyll. How to filter recent posts by category except current post?杰基尔。如何按类别过滤除当前帖子之外的最新帖子?
【发布时间】:2018-12-21 21:47:08
【问题描述】:

我想按类别获取页面上的最后 3 个帖子,但此过滤器中的当前页面除外。

我的代码不起作用:

{% for cat in page.categories[0] %}
    {% for post in site.categories[cat] limit: 3 %}
        {% if post.title == page.title %}
            {% break %}
        {% endif %}
      <div class="item">
        <a href="{{ post.url | relative_url }}">
            <div class="image" style="background-image: url({{ post.image }});"></div>
            <div class="item-text main">
                <h1>{{ post.title }}</h1>
            </div>
        </a>
      </div>
    {% endfor %}
{% endfor %}

【问题讨论】:

    标签: jekyll liquid jekyll-extensions


    【解决方案1】:

    你可以替换

    {% if post.title == page.title %} {% break %} {% endif %}

    {% unless post.url == page.url %}

    完整代码

    {% for cat in page.categories[0] %}
    {% for post in site.categories[cat] limit: 3 %}
        {% unless post.url == page.url %}
      <div class="item">
        <a href="{{ post.url | relative_url }}">
            <div class="image" style="background-image: url({{ post.image }});"> 
            </div>
            <div class="item-text main">
                <h1>{{ post.title }}</h1>
            </div>
        </a>
      </div>
     {% endunless %}    
    {% endfor %}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 2021-10-26
      • 2020-11-10
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多