Reputation: 2546
I am new to Jekyll. I know that Jekyll supports to show recent post with the following code:
<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>
But I would like not to show a category of posts, saying the category name is "notshowing"
. How can I make it?
Upvotes: 3
Views: 383
Reputation: 23962
To avoid showing a specific category you can use the unless
filter:
executes a block of code only if a certain condition is not met (that is, if the result is false).
So for example, inside the for
loop, use {% unless post.categories contains "notshowing"%}
In your example, using the site posts site.posts
instead of paginator.posts
(you can adjust that to fit what you need) it would look like:
<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>
Upvotes: 4