There are some great options to do prev/next entries (Advanced Prev/Next, Nearby Entries, etc.) but I could not find an add-on or an EE-native way to do a "Go to Next Category" and/or "Go to Previous Category".
Am I missing something obvious?
As mentioned, you can easily do this with the query
module. I've done something very similar, but you could pass the needed variables to an embed to get the prev/next category.
[removed] see updated answer below
Depending on how your categories are ordered (alphabetical or custom) & nested a few more variables are needed. You will need to use an add-on like GWcode Categories to get the necessary variables for a query, specifically cat_order
, which GWcode gets.
Parent Template:
{exp:gwcode_categories
cat_url_title="{segment_3}"
limit="1"
}
{embed="some/template" cat_url_title="{cat_url_title}" group_id="{cat_group_id}" parent_id="{parent_id}" cat_order="{cat_order}"}
{/exp:gwcode_categories}
Embded
{exp:query sql=
"SELECT
cat_url_title as prev_cat_url_title,
cat_name as prev_cat_title
FROM exp_categories
WHERE cat_url_title <> '{embed:cat_url_title}'
AND parent_id = {embed:parent_id}
AND group_id = {embed:group_id}
AND cat_order = {emebd:cat_order} - 1
LIMIT 1"
}
<a href="../{prev_cat_url_title}/">{prev_cat_title}</a>
{/exp:query}
For next category, change the cat_order
clause to:
AND cat_order = {emebd:cat_order} + 1
Master Sort Order
I wrote some code a while back that stepped through categories to generate lists the way I wanted them. While {exp:query}
is the go-to solution for a lot of category interaction, you can't just use SQL to get these, you need to follow the logic that EE uses to order them.
You can check out the recursive subcategories add-on on Github if you want to try to whip up a plugin that does the same. There's a link to a fork that ports it to EE2.