Chief Alchemist - Business Consulting For The 21st Century Via A Holistic & Intelligent Approach
Share RSS 2.0 feed for Sign up for the mailing list. Follow Chief Alchemist on Twitter. 'Like' the Chief Alchemist's page on Facebook. See what Chief Alchemist has been Q&A'ing on Quora. Chief Alchemist bookmarks & highlights on Follow the Chief Alchemist on Chief Alchemist channel on Chief Alchemist on Flickr. Mark 'Chief Alchemist' Simchock on LinkedIn. Free Initial Consultation. Email Chief Alchemist. Phone Chief Alchemist.
  • Mark ‘Chief Alchemist’ Simchock
  • 'Email me.Email => ca .at. ChiefAlchemist .dot. com
  • 'Phone me.Alchemy United => 732 997-0028
  • Free initial consultation.Free => Initial Consultation
  • Please be sure to subscribe to your communication channels of choice.
  • Click To Close => The small green (consultation), red (email) or blue (phone) icons in the top upper right.
Business Consulting For The 21st Century Via A Holistic & Intelligent Approach

Expression Engine: Nested category pairs

Using an outer category loop to define which entries of an inner channel loop is pretty straight forward. EE gets sticky when you also need to list any categories associated with a channel entry of that inner loop. What EE does is apply the outer loop’s category group to the inner (channel entry) categories.

It does not error, It just parses in a way one probably doesn’t expect. Bug? Probably not. Quirk? Yup, it does seem that way.

The solution is to use a SQL statement on the outside instead of a {categories} loop pair. The pseudo-code looks something like:

1 – {exp:query sql=”SELECT * FROM  exp_categories WHERE group_id =’_#_’ ORDER BY cat_order ASC “}
2 -{exp:channel:entries channel=”support” category=”{cat_id} ” }

3 -Channel info you want to display.

4 – {categories show_group=”_?_”}
5 – {category_name} .
6 – {/categories}

7 – {/exp:channel:entries}
8 – {/exp:query}

The {cat_id} in Line 2 is from the outer loop. In other words, the Line 1 outer loops says, “Let’s loop thought this category group.” Line 2 says, “For the {cat_id} specified in the outer loop, show the channel entries where there’s a match.”  Finally, Line 4, 5 & 6 spits out the categories for each channel entry that fit the criteria defined by an outer look.

That’s it. Simple but handy.

  1. Robert Wilson

    thanks for the post

  2. Adam Smith

    This just SAVED my day. Thanks a lot.

Will not be published. Required.
Please include http://