1

I have entries which are assigned to two category groups. In one category group, the entry will only every belong to one category.

Is it possible to order entries alphabetically by category group? Something like:

orderby="category_group:2" sort="asc"

?

3 Answers 3

2

Also have a look at NSM categories by EE-garage

http://ee-garage.com/nsm-categories

1
  • Ooooh, that looks very promising - thanks for the tip!
    – Katrin
    Commented Feb 12, 2013 at 16:03
2

This should do the trick. The category tables' structure in ExpressionEngine is really simple and using SQL is more powerful than any of EE's category tags:

You'll need to enable the Query module if you haven't.

{exp:query
sql="Select g.group_name, c.cat_name, t.title, t.url_title
From exp_category_groups g
join exp_categories c
on g.group_id = c.group_id
join exp_category_posts cp
on c.cat_id = cp.cat_id
join exp_channel_titles t
on cp.entry_id = t.entry_id
where g.group_id = 4
order by g.group_name, c.cat_name, t.title asc"}
{if ...}<h2>{group_name}</h2>{/if}
{if ...}<h3>{cat_name}</h3>
<ul>{/if}
<li><a href="{url_title}">{title}</a></li>
{if ...}</ul>{/if}

I didn't fill in the if statements. You'll need some conditional logic to figure out when in the loop to show a group or category heading and start a new list, because those are on every result returned. That might need to be PHP, so you can keep track of the previous value and compare them.

GWCode Categories also fills in many of the gaps in EE's category tags.

Updated: The exp:query tag is a great technique to master, as it offers 'middle ground' between EE's tags and doing custom PHP/app dev. You're right (in your comment) that you'll lose out on some built-in parameters, but you may be able to include some in your SQL. Check out GWCode Categories too, though. It might offer solution and its docs include plenty of examples.

3
  • Thank you for your quick reply. This is rather out of my comfort zone, as the channel loop already contains a host of other parameters besides this one... I had a hunch there wasn't a way to do this with the channel:entries loop, so I'll probably add a text field for this to enter the category name again.
    – Katrin
    Commented Feb 12, 2013 at 13:55
  • Hi Katrin, I updated the answer with a bit of follow up. Commented Feb 12, 2013 at 14:15
  • Thanks Mark. I am already using GWcode Categories and agree, it's fantastic for working with categories. I'll have another look if I can somehow combine it with the channel loop to get what I want...
    – Katrin
    Commented Feb 12, 2013 at 15:58
0

I'm not sure I totally understand your question, but Low's Reorder add-on is really useful for working with categories and unique sorting options. I suspect it may help you tackle what you're describing. http://gotolow.com/addons/low-reorder

And if you're not already familiar with it, his Seg2Cat add-on is definitely worth a look too. It doesn't relate to your question specifically, but it's super useful and can make certain category related tasks much, much easier:
http://gotolow.com/addons/low-seg2cat

1
  • That add-on is for the sorting entries in the Control Panel, I want to sort templates via the channel:entries loop in my template. Already using Seg2Cat, thanks though.
    – Katrin
    Commented Feb 12, 2013 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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