Jekyll 在liquid中循环浏览不属于某个类别的所有帖子列表
我想循环浏览网站上的帖子,但类别Jekyll 在liquid中循环浏览不属于某个类别的所有帖子列表,jekyll,liquid,Jekyll,Liquid,我想循环浏览网站上的帖子,但类别未列出的帖子除外。我可以通过在for循环中嵌套if语句来实现这一点,但当我还想指定限制时,这会发生故障,无论post是否通过检查,循环都只会运行5次 {% for post in site.posts limit: 5 %} {% unless post.categories contains 'unlisted' %} <!-- display post --> {% endunless %} {% endfor %} 您可以使用计数器
未列出的帖子除外。我可以通过在for循环中嵌套if语句来实现这一点,但当我还想指定限制时,这会发生故障,无论post是否通过检查,循环都只会运行5次
{% for post in site.posts limit: 5 %}
{% unless post.categories contains 'unlisted' %}
<!-- display post -->
{% endunless %}
{% endfor %}
您可以使用计数器:
<ul>
{% assign postCounter = 0 %}
{% assign maxPost = 5 %}
{% for post in site.posts %}
{% unless post.categories contains 'unlisted' %}
<li><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a></li>
{% assign postCounter = postCounter | plus: 1 %}
{% if postCounter >= maxPost %}
{% break %}
{% endif %}
{% endunless %}
{% endfor %}
</ul>
{%assign postCounter=0%}
{%assign maxPost=5%}
{site.posts%中的post为%s}
{%除非post.categories包含“未列出”}
{%assign postCounter=postCounter | plus:1%}
{%if postCounter>=maxPost%}
{%break%}
{%endif%}
{%end除非%}
{%endfor%}
<ul>
{% assign postCounter = 0 %}
{% assign maxPost = 5 %}
{% for post in site.posts %}
{% unless post.categories contains 'unlisted' %}
<li><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a></li>
{% assign postCounter = postCounter | plus: 1 %}
{% if postCounter >= maxPost %}
{% break %}
{% endif %}
{% endunless %}
{% endfor %}
</ul>