2

Is it possible to create a single alphabetically ordered list containing categories from multiple category groups?

Here is the code I am using:

<ul>
    {exp:channel:categories category_group="1|2"}
         <li>{category_name}</li>
    {/exp:channel:categories}
</ul>

Unfortunately this separates the category groups, and I end up with a list such as this:

  • book
  • graphic identity
  • poster
  • website
  • architecture
  • art
  • David Bowie
  • ExpressionEngine
  • zoos

You'll notice that it is actually two lists ordered alphabetically. I would like to merge these into one list somehow.

I would expect to be able to add something like orderby= as in the Channel Entries Tag:

<ul>
    {exp:channel:categories category_group="1|2" orderby="name"}
         <li>{category_name}</li>
    {/exp:channel:categories}
</ul>

But this does not work. Has anyone come across this before?

Many thanks in advance.

1

GWcode Categories may be more helpful to you.
You can do a whole lot more with categories than the native solution.

I would be very surprised if it couldn't do what you need.

OR
Use Stash.

Get all the categories you need, don't worry about the order.
Once they are stashed, they become one single list.

{exp:stash:set_list name="categories" parse_tags="yes"}
  {exp:channel:categories category_group="1|2"}
    {stash:name}{category_name}{/stash:name}
  {/exp:channel:categories}
{/exp:stash:set_list}

Then just output them all in the order you need.

<ul>
{exp:stash:get_list name="categories" orderby="name"}
  <li>{name}</li>
{/exp:stash:get_list}
</ul>
| improve this answer | |
  • Hi Jason, thanks for your answer. I'll look into those options. I take it there is not a way to do this without using any add ons then? – Sam Baldwin Apr 11 '13 at 13:24
  • I can't say for sure... But, I would have tried the same code as you did, and it appears not to work. – Jason Varga Apr 11 '13 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.