Jekyll截断一些博客文章有条件排除一些

时间:2017-08-14 06:55:28

标签: arrays jekyll limit blogs liquid

在我的Jekyll网站上,我有一个概述页面,其中列出了我最近的10篇博文。

但是,我还为我的一些博文和我不想展示的博文分配了一个标记exclude。这有效,但后来我没有收到最近10篇博文,但10篇减去了exclude博客帖子的数量。

以下是这样的:

---
layout: page
title: "Last posts"
permalink: /last/
---

### Last posts

{% for post in site.posts limit:10 %}
    {% unless post.category == "exclude"%}
      * {{ post.date | date_to_string }} » [ {{ post.title }} ]({{ post.url }})
    {% endunless %}
{% endfor %}

如何始终显示最近10篇非exclude博文?

1 个答案:

答案 0 :(得分:1)

显示最近10篇非排除博客文章:

  1. 创建一个包含不包含exclude标记的帖子的数组。

    {% assign nonexcludeposts = ''|split:''%}
    {% for post in site.posts %}
        {% unless post.category == "exclude"%}
        {% assign nonexcludeposts = nonexcludeposts|push:post%}
        {% endunless %}
    {% endfor %}
    
  2. 显示10个最近的帖子

    <ul>
    {% for post in nonexcludeposts limit:10 %}
          <li>
          <a href="{{post.url|absolute_url}}">{{post.title}}</a>
          </li>
    {% endfor %}
    </ul>
    
相关问题