How can I make URL reflecting Drupal's term structure realized by using Pathauto module?

79 Views Asked by At

There is a vocabulary like the one below and its term.

Vocabulary

World [Machine Name: world]

Taxonomy Terms

USA [URL Alias: usa]
 └─ California [URL Alias: usa/california]
       └─ Los Angeles [URL Alias: usa/california/losangeles]

And I would like to use the Pathauto module and make the URL of the losangeles term page as http://example.com/usa/california/losangeles.

In other words, the machine name of the vocabulary is taken as the root directory, And I want to make URLs synchronous with the hierarchical structure of terms belonging to that vocabulary a path lower than that. And I want to use tokens of Pathauto.

In that case, how can I set it in the Pathauto setting page(/admin/config/search/path/patterns)?

I tried many kinds of patterns, but it did not work. The version of Drupal is 7.52.

If you know the solution, please let me know. Thank you very much.

1

There are 1 best solutions below

0
melvin On

You should really look at the token suggestions that the patterns page give you. Under the taxonomy token you will find the parents token.

Parents [term:parents] An array of all the term's parents, starting with the root.

This is an array that has an other token again that lets you join them together.

Joined path [term:parents:join-path] The array values each cleaned by Pathauto and then joined with the slash into a string that resembles an URL.

Now you have the path ready made for you upto the term you are on, that one you will need to add yourself with term:name.

Giving you a path:

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

This will generate the correct path for you no mather how deep so

Usa which has no parents and the name usa will generate:

/usa

California has one parent named usa and is named California will generate

/usa/california

And the last one 2 parents named usa and california will be joined together into /usa/california and is named Los Angeles and will result into

/usa/california/losangeles