Skip to content

Instantly share code, notes, and snippets.

@roachhd
Last active September 26, 2019 21:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roachhd/ff66af9fd920a15c75a3 to your computer and use it in GitHub Desktop.
Save roachhd/ff66af9fd920a15c75a3 to your computer and use it in GitHub Desktop.
Jekyll - Get a list of PAGES in a given Category -not posts- for

on _config.yml add your index of categories:

categories: [bacon, dogs, cows, mull, stink]

on your page.md inside the front matter add one or more of the categories available in the _config.yml

---
layout: page
title: Stinky Trees
description: Mull Congress from stinky trees.
categories: [stink, mull]
---

on your template to get all the pages in the stink category you do:

{% for page in site.pages %}
  {% if page.categories contains 'stink' %}
    <div class="item">
      <h3><a href="{{ page.url }}">
        {{ page.title }}
      </a></h3>

      <p>{{page.description}}</p>  
    </div>
  {% endif %}
{% endif %}
@gene1wood
Copy link

There's a syntax error in this, there's an endif that should be an endfor. The template should look like

{% for page in site.pages %}
  {% if page.categories contains 'tech' %}
    <div class="item">
      <h3><a href="{{ page.url }}">
        {{ page.title }}
      </a></h3>

      <p>{{page.description}}</p>
    </div>
  {% endif %}
{% endfor %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment