Skip to content

Instantly share code, notes, and snippets.

@roachhd

roachhd/README.md

Last active Sep 26, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@gene1wood gene1wood commented Sep 26, 2019

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