Drupal 7: Pathauto hierarchical taxonomy terms pat

2019-03-29 11:58发布

问题:

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.

回答1:

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]



回答2:

In your particular situation you can go away with using following pattern for taxonomy items:

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

And for node pattern:

[node:%field_taxonomy%:url:path]/[node:title]

There is downside tho - term pattern will handle up to three levels in this case. So you can not make it unlimited with this approach. (I believe you can add term:parent:parent:... as many as you want).

Although, it will handle LESS than 3 levels fine (just tested to make sure).



回答3:

As far as I know, basic Drupal + Token + PathAuto is not able to create paths, like you want them to.



回答4:

Check my answer here. You can use the taxonomy entity index module for achieving such behaviour.