14

Pathauto seems to have a different way of aliasing taxonomy hierarchy.

From Taxonomy Menu:

  1. Classifieds > Cars > Aston Martin > DB9 Coupe
  2. Classifieds > Jobs > Accounting

What I want is something like this for the url:

  • classifieds/jobs/accounting (not accounting-jobs-classifieds)

(Note that Pathautho generates this with dashes in reverse order as well.)

In Pathauto, I'm using this pattern: Default path pattern (applies to all vocabularies with blank patterns below)

[term:parents-all]

Confused.

5 Answers 5

9

With the Token module enabled, you can set a pattern like this:

[term:vocabulary]/[term:parent:parent:name]/[term:parent:name]/[term:name]

Make this pattern as long as you want. Your paths will then become:

vocabulary
vocabulary/category1
vocabulary/category1/subcategory1
vocabulary/category1/subcategory2
vocabulary/category1/subcategory2/subsubcategory1

and so on...

2
  • Many Thanks to you! So if i have a taxonomy hierarchy 5 levels deep (including vocab) that would be [term:vocabulary]/[term:parent:parent:parent:name]/[term:parent:parent:name]/... etc.., right? I wish tokens module can be configured in such a way you don't need to define parent-child repeatedly in this manner. What if unexpectedly your tree becomes 6 levels then you would have to delete and update your paths to include another and then becomes 7 levels deep and so on.. i mean, if one user added terms one level down, he cannot see his contents unless a admin updates pathauto!
    – jan
    Commented Jan 27, 2012 at 7:11
  • 1
    Even though this is the accepted answer, please review @NenadP's answer for a scalable solution.
    – Paul
    Commented Apr 21, 2015 at 17:45
16

There is a clever way to do this by using join:/

In my case, I used:

[node:field-taxonomy-skolski:parents:join:/]

where field-taxonomy-skolski is the field for choosing the term from the taxonomy tree. Forward slashes will be stripped, though there is a setting under

Administration » Configuration » Search and metadata » URL aliases » URL aliases - settings

at the bottom of the page for PUNCTUATION drop-down. Set to slash (/) "no action" instead of "remove".

4
  • Bingo! I myself offered the above non-scalable solution (drupal.stackexchange.com/questions/27141/…) and of course I like this one much better. I'd swear that token option hasn't been there when I was struggling to get that pattern working. Thanks! Commented Apr 22, 2012 at 17:53
  • 2
    [...:join:/] did not work for me but [...:join-path] did. Remark: with join-path you can not choose the separator. It just uses / as separator.
    – user25536
    Commented Jan 22, 2014 at 9:30
  • If this doesn't work for you, you probably need to install and enable the "entity" module. Commented Nov 29, 2016 at 9:07
  • Pattern for Drupal 8 is a little different, e.g.: [term:vocabulary]/[term:parents:join:/]/[term:name] Commented Nov 7, 2018 at 11:54
6

This one works for me on Drupal 7.15 with Token 7.x-1.3 and Pathauto 7.x-1.2:

[term:parents:join:/]/[term:name]

As brunops stated in the second answer, join:%separator% does the magic. It replaces the default dash with %separator%.

A big thanks to brunops!

1
  • This have to be right answer! It doesn't matter at all how many levels you have, this will work.
    – Rantiev
    Commented Jul 28, 2014 at 11:54
3

The keys to getting this to work is:

  • install and enable the Entity API, Entity Tokens, Path Auto and Taxonomy modules.
  • create a field on your content type and set Field Type to Term Reference and name it something like 'field-content-category' (machine name)
  • Set the Number of Values, aka, 'Maximum number of values users can enter for this field' to 1 (very important if you want to use the joined-path tokens which automatically adds a / between the path elements).
  • set the URL patterns (admin/config/search/path/patterns) to something like '[node:field-content-category:parents:join-path]/[node:field_content_category]/[node:title]'
0

Well I would recommend using something smart like:

[term:parent:terms:reversed:join:?]

But I cant for the life of me get it working neither. So instead I recommend the following but you can only go as deep as the hierarchy allows (can be seen in replacement patterns). If you add terms deeper in the hierarchy you will have to update the pattern also.

[term:parents-all:3]/[term:parents-all:2]/[term:parents-all:1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.