【问题标题】:Post index for posts with several conditionals (categories, language, tags) in JekyllJekyll 中带有多个条件(类别、语言、标签)的帖子的帖子索引
【发布时间】:2014-06-02 22:29:51
【问题描述】:

我想在我的 Jekyll 网站上为多个类别语言提供多个后索引(索引?),这意味着多个条件。

我的帖子有 YAML 前端,包括:

categories:
   - research
   - blog
lang: en

现在我想要一个帖子索引,因为所有的研究帖子都是英文的。

我能做到:

{% for post in site.posts %}
    {% if post.lang == 'en' and post.categories contains 'research' %}
        {{ post.title }}
    {% endif %}
{% endfor %}

然而,这搞砸了限制和按年份排序等细节。为了限制帖子的数量(等),Jekyll 似乎仍在查看整个帖子列表,不只是条件适用于谁。

这样的伪代码是理想的: {% for post in site.posts where post.lang == 'en' and post.categories contains 'research' %}

有什么想法吗?

Ps.:我不能使用任何插件;希望它与 GH Pages 兼容。 Pps.:我知道我可以使用语言作为一个类别,但感觉不对——这些是不同的信息。

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    我相信你可以做到:

     {% assign resindex = site.posts | where: "category", "research", | where: "lang", "en" | sort: "title" %}
     {% for post in resindex limit:4 %} 
     <div>
     <p><a href="{{ post.url }}">{{ post.title | truncate: 52 }}</a></p>
      </div> 
     {% endfor %}
    

    虽然我对类别和类别的使用以及何时可以/应该使用它们感到相当困惑。对于我的示例类别有效,但在我的前面问题中,我有:类别:mycategory 并且只使用一个。但是其余的代码应该可以工作,你可以限制和排序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-12
      • 2019-03-26
      • 2012-04-12
      • 2014-01-03
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多