2017-03-07 22 views
1

我是Jekyll的新手。我知道哲基尔支持显示最近的文章下面的代码:Jekyll:只显示最近的帖子,不包括一些指导者

<div id="recent-posts" class="recent-posts"> 
    {% for this_post in paginator.posts %} 
    <div class="post"> 
     <a href="{{ this_post.url }}"> 
     <h2 class="post-title">{{ this_post.title }}</h2> 
     </a> 
     {% include category_info %} 
     {% include source_info %} 
    </div> 
    {% endfor %} 
</div> 

但我想不显示职位的类别,称类别名称为"notshowing"。我怎么做到的?

回答

0

要避免展示特定类别可以使用unless滤波器:

仅执行如果某个条件没有被满足的代码块(即 是,如果结果为假)。

因此,例如,在for循环中,使用{% unless post.categories contains "notshowing"%}

在您的例子,使用本网站的帖子site.posts而不是paginator.posts(你可以调整,以适应你的需要)它会是什么样子:

<div id="recent-posts" class="recent-posts"> 
    {% for post in site.posts %} 
    {% unless post.categories contains "notshowing"%} 
    <div class="post"> 
     <a href="{{ post.url }}"> 
     <h2 class="post-title">{{ post.title }}</h2> 
     </a> 
    </div> 
    {% endunless %} 
    {% endfor %} 
</div> 
相关问题