Jekyll-获取多个类别中的所有帖子

Jekyll-获取多个类别中的所有帖子,jekyll,liquid,Jekyll,Liquid,我想循环所有被分配了类别“foo”和类别“bar”的帖子 这可能吗 在我的例子中,“foo”作为“parent”类别改为“bar”/foo/bar/_帖子 谢谢完全可以:循环浏览所有帖子,然后选择想要的帖子: {% for post in site.posts %} {% if post.categories contains "foo" or post.categories contains "bar" %} <li><a href="{{ post.

我想循环所有被分配了类别“foo”和类别“bar”的帖子

这可能吗

在我的例子中,“foo”作为“parent”类别改为“bar”<代码>/foo/bar/_帖子


谢谢

完全可以:循环浏览所有帖子,然后选择想要的帖子:

{% for post in site.posts %}
    {% if post.categories contains "foo" or post.categories contains "bar" %}
        <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endif %}
{% endfor %}
{%for site.posts%}
{%如果post.categories包含“foo”或post.categories包含“bar”%}
  • {%endif%} {%endfor%}
    您可以按第一个标记进行筛选,然后查找第二个(以及第三、第四、第五……)标记,而不是浏览每篇文章并与匹配:

    {%用于站点中的帖子。categories.fizz%}
    {%如果post.categories包含“buzz”且post.categories包含“bang”%}
    
  • {%endif%} {%endfor%}

    这比在每一篇文章上迭代要有效一些,它建立了一个
    关系,而不是
    关系。

    我尝试了这个方法,但后来我的forloop.index被取消了,我用它来编写一些分隔符元素。在我的用例中,它将是一个“and”而不是一个“and”或者“你能描述一下你的帖子是如何存储的,以及你的类别是如何定义的吗?我说了。它们是按原问题中所示的路径组织的。是的,但是你的YALM是什么样子的?你的_config.yml中有关于url的特定内容吗?”?
    {% for post in site.posts %}
        {% if post.categories contains "foo" or post.categories contains "bar" %}
            <li><a href="{{ post.url }}">{{ post.title }}</a></li>
        {% endif %}
    {% endfor %}
    
    {% for post in site.categories.fizz%}
        {% if post.categories contains "buzz" and post.categories contains "bang" %}
             <!--post has categories fizz AND buzz AND bang-->
            <li><a href="{{ post.url }}">{{ post.title }}</a></li>
        {% endif %}
    {% endfor %}