I can't wrap my head around this. I'm trying to create a pattern in pathauto to adhere to the taxonomy of the node.

In Drupal 6x, I could specify a pattern like so:

[term-raw]/[title-raw]

...which worked like a charm.

But with both Taxonomy and Pathauto having changed in Drupal 7x, I can't seem to replicate this functionality.

Under admin/config/search/path/patterns, I would like to edit the pattern for "Basic Page Paths". Right now, I've got it set to:

[node:title]

But what I would really like to do is have a pattern such as:

[term:name]/[node:title]

but the term* replacements patterns are not available for "content".

Any suggestions?

Comments

domm’s picture

Not sure how much of a help this is, but I've been able to get some taxonomy tokens in Drupal 7 by using Entity API (http://drupal.org/project/entity) and the included Entity Tokens module.

pedroweb’s picture

Also do I look that I've tried Pathauto but does not work and I want it to be so [term: name] / [node: title] but can not find any help more info

bnicoll’s picture

subscribe

artatac’s picture

Sub

gilzero’s picture

subscribe +1

darekirl’s picture

Sorry for my bad english, I've got solution : Just download latest token module and apply this path: http://drupal.org/node/741914#comment-3714746
It's working for me with pathauto and custom breadcrumbs module :)
In pathauto pattern I'm able to get tokens like this: [node:term:parent]/[node:term]/[node:title]

Here is ready pathed token module i think: http://drupal.org/node/741914#comment-4006696

awasson’s picture

Subscribe

ILLIA’s picture

Hey, guys!

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! ))

Poieo’s picture

Any one who couldn't get ILLIA's solution to work, I had to flush the site's cache before the token was in the list and usable...

dalegrebey’s picture

Thanks much for that tidbit. I already had the Entity solution to this working, but was going bonkers when I added a new Hierarchical Select field and couldn't get it to recognize. Clearing Cache did the trick.

ziku’s picture

I did the same but it's not working any help?

The error i am receiving is: The Pattern for all Basic page paths is using the following invalid tokens: [node:field_category]

What I did ..
I created a new taxonomy vocabulary and called it "Category". Then I added two terms to this new vocabulary.
I go to Structure->Content Types->Basic Page->manage fields.

I created a new field "field_category" of type "term reference" and in the setting set the Category as its source vocabulary.

Then I go to the Configuration->Url aliases->patterns->Content Paths. I placed following tokens under basic page text:
[node:field_category]/[node:title]

Upon saving it gives the error: The Pattern for all Basic page paths is using the following invalid tokens: [node:field_category]

I tried to change the token text to [node:field_category:name] but it's not working.

I also tried with different labels for this field like: "Category", "Category;" or simply ";" still no result.

clear cache didnt work as well.

I am using entity-7.x-1.0-beta9, token-7.x-1.0-beta2 and pathauto-7.x-1.0-rc2.

dalegrebey’s picture

Did you clear your cache?

ziku’s picture

yes - i cleared the cache

joedag32’s picture

I'm having an identical problem as to what you described. Unfortunately I haven't been able to resolve it yet.

It was working for me and I'm starting to believe that the [node:field_cateogry:name] may've disappeared when I upgraded entity to entity-7.x-1.0-beta9

ziku’s picture

Does it mean there is no solution at this time ?
And we cannot create URL alias pattern for our pages like:
example.com/category_name/node_title

ziku

Poieo’s picture

It's working for me with [node:field-category:name] using entity beta8. If you guys are both using beta9, then something must have changed.

ziku’s picture

i tried with both entity beta 8 and 9. no luck

ziku’s picture

I tried different scenarios and it's working now. In my case there was a logical mistake.
Under Content types » Basic page » Manage fields I was setting the Maximum number of values users can enter for term field >1. I set the maximum value to 1 and it works.
I think the error message at the pattern setting page should be more user friendly and according to the mistake.
Any ways now it's working and thanks for everybody for help and guidance.
ziku

joedag32’s picture

That's great. I tried what worked for you as well as upgraded to 7.x-1.0-beta10 and cleared the caches and all seems to be working well for me too!

Summit’s picture

Bookmarking. greetings, Martijn

waynedpj’s picture

ahoy ziku,

similar to your comment, i had created a Categories Vocabulary, added it to the Basic Page content type as a field, and was trying to create a Path Auto pattern that would give a URL of parent-term/child-term/node-title . like you, i had set the maximum field count for the Categories field to unlimited, which never gave a parent pattern in Path Auto patterns, making the desired URL impossible.

following your suggestion of setting the maximum field values to 1 has allowed me to use a pattern of "[node:field-categories:parent:url:path]/[node:field-categories:name]/[node:title]" to achieve the desired URL. thanks!

a side effect of this is that a piece of content can no longer be in more than 1 Category (which parent replaces the parent:token in the URL?). with this restriction, the Category taxonomy basically acts like the regular node Menu link. so perhaps it would be better to use the Menu and not define a taxonomy to do the same thing (better because every node already has a menu field, no need for a new Taxonomy Vocabulary and new field on each Content Type), but i have yet to find a way to duplicate the Vocabulary's features of a summary page and a feed. any comments on this appreciated.

thanks again for the fix.

peace

genox’s picture

I played around with this for a bit and one option I got to work is to create 2 select-widgets for the same vocabulary. Let's call them "primary" and "secondary". Create the URL alias based on the primary selection only, but selecting a second term makes the node available also on the secondary taxonomy term page. Of course one can add even ore widgets. However, depending on the total amount of data, it probably makes sense to limit the number of terms to 2-3. Otherwise, you might get a lot of duplicate content on term pages. But I didn't test that..

However, your mileage may vary: I'm using the module taxonomy_display which allows you to change the taxonomy term page listing to a custom view you previously create, for which you can also specify context/arguments - like "term id (with depth)" - this comes in extremely handy for more complicated data listings and also, for example, to easily include child terms up to depth "x". In combination with an exposed filter or facet filter widget provided by search_api, facetapi and an apache SOLR engine => yummy data browsing. :-D

Btw.. here's the pattern I used to create nice URL aliases for a vocabulary with no limit in terms of parent terms:

[node:field-galerie:vocabulary:name]/[node:field-galerie:parents:join:/]/[node:field-galerie:name]/[node:title]

This is a nice, generic approach which also includes the vocabulary name. Works with entity and token modules, 7.x-1.0-rc1.

bbu23’s picture

I`ve searched this pattern for hours. This really helped ! Thanks a lot for sharing !

Bubu

hockey2112’s picture

Thank you, in0giro! I had the same problem, and your post made me see the light, re: maximum field values and pathauto.

mariohernandez’s picture

Changing the maximum number of values to 1 also worked for me. Originally I had set it to Unlimited and I was not able to see the right replacement patterns.

Mario Hernandez
http://designsdrive.com

ivoo56’s picture

Hi,

It worked for me with [node:field_term] where field_term is the Term reference field used in the specific content.
The new URL structure would apply to any new content or terms. Just do not know how to purge/ rebuild URL's

Hope it helps someone!

rwilson0429’s picture

Thanks so much. After 2 days of searching for a solution to this problem, I stumpled upon your solution. Your solution worked like a charm. I was trying to get the parent term to be included in the alias path (i.e. parent-term/child-term/node-title. Following your example, I used something like [node:field-category:parent]/[node:field_category]/[node:title].

Again thanks for the helpful insight, now on to the next obstacle.

P.S. After moving to production, the thing stopped working. After implementing the suggestion Posted by ziku on July 14, 2011 (setting the "Maximum number of values users can enter for this field" to 1), it started working like a charm again. Thanks Ziku, it would have taken forever for me to figure that out.

A quick summary to the solution for this issue

The keys to getting this to work is:

  • install and enable the Entity API, Entity Tokens, Path Auto and Taxonomy modules. Set
  • 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).
  • 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]'

ReggieW

Mavro’s picture

ILLIA, this has been driving me crazy on a project. I followed your instructions and it worked! You're a life saver. Thank you.

ILLIA’s picture

;))) It was also driving me crazy for several days. I didn't even understand how I came up with that solution. Think God helped :-) And I instantly decided to share it with the community.

Cheers!

knalstaaf’s picture

"Node > [my field name] > Name" works for me, thanks! (resulting in [node:menu-link:parent]/[node:field-my-field-name:name]

P.S.: the first letter of my field (term reference) is uppercase. Seems to be ok for the latest versions.

augbog’s picture

Just an FYI the default scheme that D7 uses for taxonomy terms is

taxonomy/term/number

where number is the auto-generated number that is assigned to the tag you created. You can find out what the number is by hovering over the different tags you have created (go to List terms to see this) and looking at what the link points to.

With that said, maybe make URL aliases from those. Tedious but does the job.

voross’s picture

pattern for all blog posts: [node:field-blogtype]/[node:title]
where blogtype is my custom field (taxonomy link) inserted into the blog content type.

Thanks a lot!

bobthebuilder’s picture

I got this to work as well, thanks for the information. However, how do you get the breadcrumb to show the taxonomy term? Right now I have a node alias named "big-blue" and it's assigned a taxonomy term of "MyTaxTerm" so the URL looks like the following:

http://www.example.com/mytaxterm/big-blue

But the breadcrumb trail shows:

Home > Big Blue

What I'd like it to show is:

Home > My Tax Term > Big Blue

Any suggestions?

Gaperville’s picture

Trying to change the taxonomy/term/3 to coupon/tags and do not want the numerical paths. I have used every method here in these comments and nothing seems to work.

Using Drupal 7.8, Pathauto:7.x-1.0-rc2, I'm using all the updated mods.

I've been attempting this for the last 5 hours within the pathauto module, views, researching the forums, etc. I have also cleared the cache several times after each attempt.

Using the pathauto I have tried several tokens just to see some changes and none have occurred. I am in the Patterns Tab under the Taxonomy term paths, in the field of Pattern for all Tag paths. Of course I have tried just adding coupon/tags and no go. Again, I have clicked on several Tokens and nothing seems to change. I do leave the Default Pattern Blank and I have tried other Tokens. If I could just see some kind of changes in the url path, then I feel like I can make this work.

Structure » Content types » Basic page » Manage fields
In the field settings, the are Unlimited in both the pages and articles for the tags.

Structure » Views » Structure
I have change the path from taxonomy/term/% to coupon/tags/% and have changed it to coupon/tags/ and just coupon/tags.
Have also cleared the Clear Views Cache in Structure » Views » Settings

Whew, I have gone all over other areas and other forums and cant seem to create any changes. I am totally memorized with all this.

Maybe I need another MOD or I need to edit my .htaccess file?

ILLIA’s picture

Hi Gaperville,

it seems to me that after changing your path pattern from taxonomy/term/3 to coupon/tags using tokens you forgot to do two simple things. Changing the path pattern and just saving sometimes is not enough for changes to take place, even if you've cleared the cash. So, the things you need to do:

1. While on "Patterns" tab go to the last "Delete Aliases" tab (site.com/admin/config/search/path/delete_bulk) and delete all aliases;

2. Go to the next tab "Bulk Update" (site.com/admin/config/search/path/update_bulk) and update content and taxonomy terms paths

Now the changes should take place.

MRPRAVIN’s picture

Working great.

Pravinkumar

knalstaaf’s picture

This doesn't seem to cover an alternative to the Taxonomy Token module (D6 only to this very day :( ), which allows you to use a taxonomy term in the url-alias of the node.

Would there be a workaround for this?

mfby2k’s picture

I was searching for this for long time but after reading this issue i tried this pattern and it worked.

[node:field-category:parent]/[node:field-category]/[node:title]

larowlan’s picture

for those of you who don't have [node:field-category:name] and only have [node:field_category] and already have entity_token - you may have a version of uuid that was fooing up tokens see: #1423542: Rewrite token integration to be more entity generic - in my case all of my [node:field-category:name] style tokens stopped working (which also broke Drupal commerce) turned out to be uuid.

HTH

Lee Rowlands

--author="larowlan <larowlan@395439.no-reply.drupal.org>"
re-present’s picture

subscribing

www.re-present.com | communications and design consultancy | open source / fashion / ideas for sustainability

audster’s picture

subscribe

Don't panic! Whatever you do, don't panic! Unless, of course, you didn't make a backup - then by all means freak out...

rwilson0429’s picture

If you use the 'Joined path' token in the latest dev version of Token module, your url path will include the parent and the ancestors.

To have the parent and all ancestors of the term appear in the path, use [node:field-content-category:parents:join-path] in your path pattern. This token returns the array values each cleaned by Pathauto and then joined with the slash into a string that resembles an URL.

ReggieW

BrianLewisDesign’s picture

[node:menu-link:parent:url:path]/[node:title] -- this repeats the top level parent multiple times, for nth children in the menu. makes a mess. doesn't get the full heirarcy.

[node:menu-link:parent:parent:parent:parent:url:path]/[node:title] -- this gets the top parent only, with no repeats, down to the 4th child in the menu.

[node:menu-link:parents:join-path]/[node:title] -- perfect. this gets the whole parent menu hierarchy into the URL. that's what i was after.

My Drupal contributions are happily supported by my company BusinessWire.

bohmann’s picture

[node:field-content-category:parents:join-path] sometimes works, sometimes fails.

I have two Drupal installations with the Entity API enabled where [node:field-content-category:parents:join-path] works in one and fails in the other. /admin/config/search/path/patterns have these Replacement Patterns / Tokens available in Nodes > Tags:

1) Drupal installation where [node:field-content-category:parents:join-path] WORKS (/admin/config/search/path/patterns): [node:tags:parents-all], [node:tags:parents], [node:tags:parents:join:?], [node:tags:parents:join-path], [node:tags:parent:parents-all], [node:tags:parent:parents].

2) Drupal installation where [node:field-content-category:parents:join-path] FAILS (/admin/config/search/path/patterns): [node:tags], [node:tags:1], [node:tags:2], [node:tags:3].

It could be a module, or settings in a module that make the difference (how can I debug that?).

/Kristoffer :-)

jay-dee-ess’s picture

Kristoffer,
Did you figure out what was going on with the install that failed?

I'm having the same problem.
-john

Jawi’s picture

I need this url path rewrite to get a clear site structure.

For the taxonomy structure this works fine:
[term:parents:join-path]/[term:name]

But how can I get my url rewrite for node pages like this?
[term:parents:join-path]/[term:name]/[node:title]

Something like this doesn't work:
[node:taxonomy-catalog:1:parents:join-path]/[node:title]

Thank u for all ideas!

Practice what you preach >> www.jawi-online.nl >> Full service internet bureau >>

Jawi’s picture

this one worked for me

[node:taxonomy-catalog:0:parents:join-path]/[node:taxonomy-catalog:0:name]/[node:title]

catalog 0 isn't displayed in the variable list.

Practice what you preach >> www.jawi-online.nl >> Full service internet bureau >>

kirie’s picture

Yay Jawi - thanks! That worked for me as well (did not have either 0 or join-path in the list of available tokens)

jiakomo’s picture

thanks!

flatfeat’s picture

Yes, thank you. This is what worked for me:

[node:field-product-category:0:parents:join-path]/[node:field-product-category:0:name]/[node:title]

where the machine name of my taxonomy was "product_category"

Produces a URL such as: candy/peppermints/york-peppermint-patties

fazni’s picture

it Work for me tks

dangswiss’s picture

I added the token pattern like this: [node:field-example-vocab:parents:join-path]/[node:field-example-vocab:name]/[node:title] without the 0's and that worked like a charm. It even worked with child terms 3 levels deep!