Jekyll 杰基尔:除了一个有限制的类别外,列出所有类别都会打破限制
我试图输出一个名单的职位标题与5个最新的职位在所有类别,但一个。它可以很好地进行过滤,不幸的是,它考虑到了被排除在外的帖子的限制。有没有简单的方法不计算被排除在外的职位Jekyll 杰基尔:除了一个有限制的类别外,列出所有类别都会打破限制,jekyll,Jekyll,我试图输出一个名单的职位标题与5个最新的职位在所有类别,但一个。它可以很好地进行过滤,不幸的是,它考虑到了被排除在外的帖子的限制。有没有简单的方法不计算被排除在外的职位 {% for post in site.posts limit: 5 %} {% if post.category == "news" %} //Do nothing {% else if %} {{ post.title }} {% endif %} {% endfor %}
{% for post in site.posts limit: 5 %}
{% if post.category == "news" %}
//Do nothing
{% else if %}
{{ post.title }}
{% endif %}
{% endfor %}
您应该能够首先分配帖子,然后调用它们:
{% assign relevant = site.posts | except:"category","news" %}
{% for posts in relevant limit:5 %}
{{ post.title }}
{% endfor %}
更多信息:要限制筛选的帖子,您需要先筛选它们 我们创建了一系列不包含
新闻
类别的帖子:
{% assign no_news = "" | split: "" %}
{% for post in site.posts %}
{% unless post.categories contains 'news' %}
{% assign no_news = no_news | push: post %}
{% endunless %}
{% endfor %}
现在我们遍历这个新数组,将迭代次数限制为5:
{% for post in no_news limit: 5 %}
{{ post.title }} - {{post.categories}}
{% endfor %}
它将输出5篇不包含
新闻
类别的帖子。不幸的是,它似乎做了完全相同的事情。它总共输出3个项目,跳过2个新闻项目。编辑掉数组中的“限制:5”,它就像一个符咒!谢谢!