0
votes

I produced an overview page for all posts from the category "Tutorials" like this:

  <ul class="post-list">
    {% for post in site.categories.Tutorials  %}
      <li>
        <span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>

        <h2>
          <a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
        </h2>
        {{ post.excerpt }}
      </li>
    {% endfor %}
  </ul>

But now I would like to produce an index page for posts with both category "Tutorials" and category "German". But how?

The post I would like to have in this overview page is this one:

---
layout: post
title: 'German tutorial'
categories: [Tutorials, German]
---

Posts I would not like to have in this overview page are posts with a header like this:

---
layout: "post"
title: "English totorial"
categories: [Tutorials, English]
---

I tried for example:

{% for post in site.categories.Tutorials & site.categories.German  %}

but this doesn't work...

I easily would switch to tags instead of categories, if this makes it easier.

1

1 Answers

1
votes

Get the first category array : site.categories.Tutorials then sort German category posts out of it :

{% assign tutorials = site.categories.Tutorials %}
{% comment %}Creates an empty array{% endcomment %}
{% assign germansTutos = "" | split: "/" %}
{% for p in tutorials %}
  {% if p.categories contains "German" %}
    {% assign germansTutos = germansTutos | push: p %}
  {% endif %}
{% endfor %}
<ul>
{% for post in germansTutos %}
  <li>{{ post.title }}</li>
{% endfor %}
</ul>

You can also simply assign a tutorial category and a lang variable to your posts and filter them by the power of the where filter.

eg:

---
layout: post
title:  "Post 1"
date:   2016-01-27 00:29:55 +0100
categories: Tutorials
lang: ge
---
Post one

You can then sort your posts like this :

{% assign tutorials = site.categories.Tutorials %}
{% assign germanTutos = tutorials | where: 'lang', 'ge' %}
<ul>
{% for post in germanTutos %}
  <li>{{ post.title }}</li>
{% endfor %}
</ul>