【问题标题】:Limit jekyll post list to certain categories将 jekyll 帖子列表限制为某些类别
【发布时间】:2011-06-14 03:17:57
【问题描述】:

我有一个jekyll 网站和一个类别(称为photo),我想为一个仅列出photo 类别中的帖子的页面创建一个单独的布局。我还想将 photo 类别的帖子保留在主索引页面之外。

【问题讨论】:

    标签: liquid jekyll


    【解决方案1】:

    站点对象中的所有类别都可用,通过site.categories.photo 访问某个类别的帖子,这样您的循环将如下所示

    {% for post in site.categories.photo %}
        # render the photo post html
    {% endfor %}
    

    【讨论】:

    • 除非我误解了这个问题,否则这应该是正确的答案。
    • 确实如此。正确,但有点晚了。
    • @matb33 即不到四分之一,呵呵。
    • 我更喜欢这个解决方案,但那只是我 :)
    • @matb33 不是完整的答案,因为他的主索引页面中仍然会有 photo 帖子
    【解决方案2】:

    我只是在主索引页面中使用了{% unless %} 块来确保帖子不是照片。示例:

    {% unless post.category == "photo"%}
        {% comment %} List posts... {% endcomment %}
    {% endunless %}
    

    我用同样的方法只显示张照片。只需使用 if 而不是 unless

    【讨论】:

    【解决方案3】:

    类别也区分大小写。如果您的类别是照片,那么它将如下所示:

    {% for post in site.categories.photo %}
        # render the photo post html
    {% endfor %}
    

    如果您的类别是照片,那么它将如下所示:

    {% for post in site.categories.Photo %}
        # render the photo post html
    {% endfor %}
    

    只是我在构建过程中遇到的一个快速细节,所以我想我会分享。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 1970-01-01
      • 2015-10-14
      • 2017-02-25
      • 2014-01-03
      • 2014-01-19
      • 1970-01-01
      相关资源
      最近更新 更多