Skip to content

How to filter posts based on category #32

Discussion options

You must be logged in to vote

Hi @KurtTrowbridge,

You could get the posts for a particular category (or tag) like this:

{% assign posts = site.categories['Test'].posts %}

You could also use a where_exp filter:

{% assign posts = site.posts | where_exp: "post","post.categories contains 'Test'" %}

To loop through posts that do or do not have a particular category, you can do this:

{% for post in site.posts %}
  {% if post.categories contains 'Test' %}
    <!-- post has category -->
  {% else %}
    <!-- post does not have category -->
  {% endif %}
{% endfor %}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sskylar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants