Iain Urquhart


Injecting EE categories to Taxonomy trees…


Given that I'm now whoring myself, and waking up with dollars in my eyes - I thought I'd put some more effort into sharing some tips and tricks of various things you can do with Taxonomy.

Without further ado, the first post: an example of outputting native EE categories within Taxonomy trees.

The problem:

Say you have a basic tree structure for the 'About Us' section of a site. Your "Team" page isn't really going to be a regular static page, you want to use categories as your navigation system to let users filter people by role.

Here's our requested tree structure:

About Us
		Floor Staff

What we need to do is produce the level below 'People' by way of native EE categories - using the ever helpful exp:channel:categories tag.

The Solution

According to Taxonomy, this is going to be our tree structure... We're not including those categories at all:

About Us

The 'people' page uses a different template from the others, so we can use a different Taxonomy nav tag on the 'people' page which will display those categories.

To 'inject' our categories, we just need to know the entry_id of the people page (in this case: 20), and use the following code:

	node_active_class="active_parent has_children"
	<a href="{node_url}">{node_title}</a>
	{if node_entry_id == 20 && node_active == "active"}

So, we're looking for a node associated with an entry that has an id of 20 - when we find it, embed our template which contains our native exp:channel:categories tag (or whatever else you need).

You'll notice I've also added the node_active_class parameter too, this is because I've told Taxonomy that we're on the 'people' page by supplying the entry_id manually - but since we're injecting children, we're applying the same css class as any other node which would have children.

You might be wondering why I'd be using an embed, and not just inserting the categories tag straight in there or using a snippet... The answer is for performance. I'm using the "auto_expand" parameter so someone on the 'careers' page shouldn't be seeing the 'people' categories - if I didn't use an embed EE would still be doing the donkey work executing the tag if it wasn't in an embed.

Was this useful? Useless? Feedback/questions in the comments is welcome. If you need support and have purchased a license, head over to the devot:ee forums for Taxonomy and start a discussion.

If you haven't tried Taxonomy yet - why not take it for a spin see what it can do. For $25USD and a 30 day money back guarantee, the folks at Devot:ee will hook you up, yo.

Comments for this entry

John Faulds
2011 06 22

Definitely useful. I haven’t come across a situation yet where I’d use it, but good to know for future reference.

↑ Back to top