Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jekyll,Liquid-从页面中获取类别中的所有页面_Jekyll_Liquid - Fatal编程技术网

Jekyll,Liquid-从页面中获取类别中的所有页面

Jekyll,Liquid-从页面中获取类别中的所有页面,jekyll,liquid,Jekyll,Liquid,我有一个关于杰基尔液体的问题 我有一个布局,我想在这里显示类别中的页面。要显示类别,我使用page.categories变量。当我在括号中显示时,{page.categories}是正确的。 但我不知道,如何传递到循环 {% for post in site.categories[page.categories] %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% end

我有一个关于杰基尔液体的问题

我有一个布局,我想在这里显示类别中的页面。要显示类别,我使用page.categories变量。当我在括号中显示时,{page.categories}是正确的。 但我不知道,如何传递到循环

{% for post in site.categories[page.categories] %}
    <li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}


{% for post in site.categories[{{page.categories}}] %}
    <li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
{%用于在site.categories[page.categories]}
  • {%endfor%} {%用于站点中的帖子。类别[{{page.categories}]]}
  • {%endfor%}
    不要工作

    如果我通过了说明:

    {% for post in site.categories['cat1'] %}
        <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endfor %}
    
    {%用于站点中的帖子。类别['cat1']%}
    
  • {%endfor%}
    它起作用了

    我发现了另一个话题:


    但是它不起作用。

    页面。类别是一个列表(请参阅),因此您需要首先循环浏览它,然后将每个类别传递给问题的循环:

    {% for cat in page.categories %}
      <h1>{{ cat }}</h1>
      <ul>
        {% for post in site.categories[cat] %}
          <li><a href="{{ post.url }}">{{ post.title }}</a></li>
        {% endfor %}
      </ul>
    {% endfor %}
    
    {%用于page.categories%}
    {{cat}}
    
      {%用于站点中的帖子。类别[cat]}
    • {%endfor%}
    {%endfor%}

    这将首先按降序显示页面第一个类别的所有帖子,然后按降序显示页面第二个类别的所有帖子,依此类推。

    谢谢。这是工作。

    我还可以使用此代码(在数组的元素上使用first,因为在我的示例中,每页只有一个类别):

    {%assign pcat=page.categories%}
    
      {site.categories[pcat.first]%中的帖子占% {%endfor%}
    {% assign pcat = page.categories %}
    
    <ul>
        {% for post in site.categories[pcat.first] %}
            <li {% if post.url == page.url %}class="active"{% endif %}><a href="{{ post.url }}">{{ post.title }}</a></li>
        {% endfor %}
    </ul>