leofontes
leofontes

Reputation: 927

IF logic in jekyll markdown

On my jekyll blog there is already a page that lists all the categories and all their respective posts, here is the code:

{% for category in site.categories %}
<div class="col-md-12 content-panel articles">
  <h2 id="{{ category | first }}-ref">{{ category | first }}</h2>
  <ul style="list-style: none;">
    {% for posts in category %}
      {% for post in posts %}
        <li>
          <!-- problem of for cycle can't use images <img src="/{{ post.header-img | prepend: site.baseurl }}" class="img-responsive" alt="{{ post.title }}"> -->
          <h3><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a></h3>
          <small class="hidden-xs">{{ post.date | date: "%B %-d, %Y" }}</small>
        </li>
      {% endfor %}
    {% endfor %}

  </ul>
</div>
{% endfor %}

My question is, how can I show only the posts on categoryX for example?

I realize this is probably something simple but couldnt find anywhere how to, I tried changing for posts in category to for posts in categoryX but it didnt work

Upvotes: 1

Views: 132

Answers (1)

marcanuy
marcanuy

Reputation: 23982

To list a specific category you can specify it using site.categories.CATEGORY so it list all Posts in category CATEGORY.

For example, if you have a category called "diet" the you can filter its posts with {% assign posts = site.categories.diet %}{% for post in posts %}.. or {% assign posts = site.category['diet'] %}

Look at some of the Jekyll variables here: https://jekyllrb.com/docs/variables/

Upvotes: 1

Related Questions