Skip to content

Instantly share code, notes, and snippets.

@shaneturner
Created December 4, 2017 00:26
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneturner/ce03a2b71db9f034e90ba25b1963b2b8 to your computer and use it in GitHub Desktop.
Save shaneturner/ce03a2b71db9f034e90ba25b1963b2b8 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 %}
@OneMohrTime
Copy link

Had to edit a Craft 2 website and this little snippet saved me a couple hours, thank you!

@shaneturner
Copy link
Author

Most welcome! Glad past-me could help out.

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