Iain Urquhart

Taxonomy

Node Custom Fields

Taxonomy 1.1 sees the introduction of custom fields for nodes within Taxonomy Trees. This means that trees can house much more than just a Label, Template Select and URL Override…

You’re now able to add custom css classes, title attributes, ‘open in new window’ checkbox, whatever you need :) Fieldtypes available are Text Input, Textarea, and Checkbox. Checkbox values when checked, are returned as ‘1’.

Usage Example

Here’s what the stock Edit Node interface looks like, without any custom fields.

Stock Taxonomy field

Lets say I want my publisher to be able to add a ‘Title’ attribute to each link, and as a developer, I wouldn’t mind being able to attach an additional class to each link too. My tree also has a few external links and my client is demanding I add target=“_blank” to those too. Sigh.

Simply visit the tree properties page and add some new custom fields like so:

Taxonomy custom fields

Now when we return to the edit node interface, we’ll see our shiny new custom fields:

Edit node interface

AND, there’s more… Custom fields can also be output to the Fieldtype, so publishers have access to your selected custom fields, right from the publish page :)

Custom fields in the custom field :)

Code Example

So here’s a stock standard Taxonomy nav tag

{exp:taxonomy:nav tree_id="1" entry_id="{entry_id}"}
    <a href="{node_url}">{node_title}</a> 
{/exp:taxonomy:nav}

With the use case of above, here’s how we’d get it working

{exp:taxonomy:nav tree_id="1" entry_id="{entry_id}"}
    <a href="{node_url}"
    	{if target_blank} target="_blank"{/if}
    	{if title_attribute} title="{title_attribute}"{/if}
    	{if css_class} class="{css_class}"{/if}>{node_title}</a> 
{/exp:taxonomy:nav}

Some important things to consider

You’ve got full control over variable names so it’s probably best you give your custom fields a prefix so they don’t conflict with any system variables, or other custom fields you may use. Use common sense.

Changing a field shortname will not update nodes with values already set, so choose your field short names wisely :)

Want to say 'thank you'?

If you find any of my work useful, feel free to make a donation amount of your choosing via PayPal — or if you like, purchase a copy of Introvert from Devot-EE and you'll get something in return :)

↑ Back to top