Jekyll,Liquid-从页面获取类别中的所有页面 [英] Jekyll, Liquid - Get all pages from category from page

查看:84
本文介绍了Jekyll,Liquid-从页面获取类别中的所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jekyll Liquid中有一个问题.

I have a question in Jekyll Liquid.

我有布局,我要在其中显示类别的页面.为了显示类别,我使用page.categories变量.当我在括号{{page.categories}}中显示时是正确的. 但我不知道如何传递循环?

I have layout, where I want to show pages from category. To show category I use page.categories variable. When I show in bracket {{page.categories}} is correct. but I don't know, how to pass to loop?

{% 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 %}

不工作.

如果我通过显式显示:

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

有效.

我发现了另一个主题:

Jekyll site.categories.{{variable}}?

但这是行不通的.

推荐答案

page.categories是列表(请参见页面变量),因此您需要先遍历它,并将每个类别从您的问题传递到该遍历:

page.categories is a list (see Page Variables), so you need to loop through it first and pass each category to the loop from your question:

{% 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 %}

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

This will first display all posts for the page's first category in descending order, then all posts for the page's second category in descending order, and so on.

这篇关于Jekyll,Liquid-从页面获取类别中的所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆