Created
December 4, 2017 00:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# 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 %} |
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
Had to edit a Craft 2 website and this little snippet saved me a couple hours, thank you!