Skip to content

Instantly share code, notes, and snippets.

@masiorama
Created February 9, 2016 17:21
Show Gist options
  • Save masiorama/9e9fa6f182114ba8cb0c to your computer and use it in GitHub Desktop.
Save masiorama/9e9fa6f182114ba8cb0c to your computer and use it in GitHub Desktop.
Craft CMS: Getting entries grouped by category in order of the category type drag & drop order.
{# Get the categories related to my "entrySection" entries in structure order #}
{% set entries = craft.entries.section('entrySection') %}
{% set relatedCats = craft.categories.relatedTo(entries) %}
{# Loop the categories #}
{% for category in relatedCats %}
{{ category.title }}
{# Get and loop through entries related to this cat #}
{% set relatedEntries = craft.entries.relatedTo(category) %}
{% for entry in relatedEntries %}
{{ entry.title }}
{% endfor %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment