Drupal 7: Pathauto hierarchical taxonomy terms pattern

Philipp Michael picture Philipp Michael · Nov 29, 2011 · Viewed 11.2k times · Source

I have a Drupal 7.9 taxonomy vocabulary according to the following scheme:

category-1
    category-1 > subcategory-1-1
    category-1 > subcategory-1-2
    category-1 > subcategory-1-3
category-2
    category-2 > subcategory-2-1

I want to reflect this taxonomy hierarchy in my page url path like

category-1/subcategory-1-1/page-123

To achieve this I'm using the modul Pathauto version 7.x-1.0. but I don't know which pattern I have to use.

Currently I'm using [node:%field_taxonomy%]/[node:title] but with this pattern the url path is just subcategory-1-1/page-123, so the complete hierarchy isn't reflected. Is there a taxonomy tree pattern? I can't find any updated information about this and valid patterns seem to change in every version of Pathauto.

Answer

across picture across · Feb 26, 2012

After some trial and error I came up with a way which works pretty good for me while creating custom URL paths using taxonomy terms. All you need to do is to install an additional module called Entity API. You can find it here http://drupal.org/project/entity. After installing you should enable both Entity API and Entity tokens modules. Entity tokens provides token replacements for all properties that have no tokens and are known to the entity API.

First, go and create a new taxonomy vocabulary. Let's call it "Category" and add some terms. Then for a content type you want to have a custom URL path you need to create a new term reference field. I don't know why but it's not working with the standart field_tags. So, make sure to create a new one. Let's also call it category and use our previously created vocabulary "Category" as the source. And here's another thing you need to take into account: you have to label this field with a small letter; otherwise it's not working for an unknown to me reason ;). You'll end up with a field_category field.

Go to URL Aliases administration page -> Patterns. Expand replacement patterns for Content paths -> expand Nodes -> you'll see category at the bottom, expand it. Ok, now you're ready to use taxonomy terms tokens.

Use something like [node:field-category:name]/[node:title] where [node:field-category:name] is the name of the taxonomy term and you'll have a path like mysite.com/term/title.

By the way, I use Pathauto 7.x-1.0-beta1, Token 7.x-1.0-beta2 and Entity API 7.x-1.0-beta8.

Good Luck! ))

http://drupal.org/node/1044980#comment-4562844

You can create url with this pattern: [node:field-category:vocabulary:name]/[node:field-category:parents:join:/]/[node:field-category:name]/[node:title]