Jekyll x Liquid 控制文章列表只显示特定类别的Post
目录
使用Liquid按照Category或者Tag过滤Post List
前段时间画了一些漫画,考虑把漫画相关的Post放到另一个页面。
这个实现还是挺简单的,直接循环Post里面特定分类下面的文章就是
{* for post in site.categories.Comic *}
<li class="ant-timeline-item">
<a href="{{ post.url}}">{{ post.title }}</a>
</li>
{* endfor *}
但是如果我想要在所有文章里面不显示特定Tag的Post该如何实现呢?
这个也很简单, 只需要立一个Flag循环判断是否含有这个Tag就行 o( ̄▽ ̄)o
{* for post in site.posts *}
{* assign flag = 0 *}
{* for tag in post.tags *}
{* if tag == TagName *}
{* assign flag = 1 *}
{* endif *}
{* endfor *}
{* if flag == 1 *}
{* continue *}
{* endif *}
<li><a href="">xxxxxx</a></li>
{* endfor *}
要注意的地方: TagName 不需要加单引号或者双引号
2017-02 Updated 另一种更简单的方法
前段时间写了个给特定post加密的功能
后来发现post 的header部分可以有很多用途, 就比如上文提到的过滤特定类别的post
我们可以在header里面这么写
layout: post
title: 《10101》EP0:我太受欢迎了该怎么办
category : Comic
tags : [Comic, 10101]
hideinpostslist: true
设置一个控制是否显示的参数为true
然后在post list页面循环判断
{* for post in site.posts *}
{* if post.hideinpostslist == true *}
{* continue *}
{* endif *}
{* endfor *}
比上面那个方法简单多了, 不过每个post需要额外设置这个参数, 如果post数量多的话还是参考上面的方法