a wee weblog, since 2006

Node URL Tag

Fetches the node's url according to Taxonomy from a given entry_id

{exp:taxonomy:node_url entry_id='{entry_id}' tree_id='1'}

Example output

http://example.com/template_group/url_title

Node URL Tag Parameters

tree_id=

tree_id="1"

The id of the tree you want to fetch. This is a required parameter.

entry_id=

entry_id="{entry_id}"

The id of the node being viewed. This is a required parameter.

Tips

If you find the following markup unsightly:

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

Create a new snippet with the name taxonomy_url_title with the tag {exp:taxonomy:node_url entry_id='{entry_id}' tree_id='1'} as the Variable Content

This will 'clean' the above markup to:

<a href="{taxonomy_url_title}">{title}</a>

Remember though, in this example, we're specifying the tree id, so if you want to use for multiple trees, you'll need to create multiple snippets.

Notes

The first time the tag is called, it stores an array of each node [entry_id] => [node_url] in the user's session. Each subsequent request is accessed directly from there so the amount of queries from 20 instances of this tag on the same page is at most, 1 query.

It's also worthwhile noting that so long as a node exists for the entry, the url generated by this tag will keep itself updated should the template names be updated, or the url_title of the entry be updated.

This tag should also work in search results to bring the user to the correct template as specified in Taxonomy. However, you may need create a workaround with conditionals if you have multiple trees using the same weblogs.

As captured 26 April 2010 · The archived original