Hey everyone, what i'm trying to do with pathauto is to make my urls work this way:
sitename.com/%content_type%/%content_type_id%
The trickiest thing is that this %content_type_id% shouldnt just be the node id, but the own id of the node exactly in that content type.
For example: i have two content types: news and videos with some nodes in them.
With no aliases they would be displayed as: sitename.com/node/1, sitename.com/node/2 etc. (regardless the content type), using a pathauto pattern with a [node:nid] replacement token i can make them look like this:
sitename.com/news/1
sitename.com/video/2
sitename.com/video/3
sitename.com/news/4
etc. the problem is of course that it still uses the node id, so sitename.com/news/3 & sitename.com/news/4 won't exist, which is not that fancy. What i want them to look like is how you could already guess this:
sitename.com/news/1
sitename.com/video/1
sitename.com/news/2
sitename.com/video/2
etc. the problem is that such a token like [node:content-type:node-id] does not exist.
The only existing one (I found)
that could work is [node:content-type:node-count], but this one isn't really the ID, it's the node count, what that means is as soon i delete one of my older nodes the whole url structure will brake (it will use urls like sitename.com/news/3-0).
There should be a way to make them look the way i want.
Any help would be appreciated, thx.
Comments
Comment #1
dave reidThere really isn't anything like this in Drupal core to get a unique ID by content type. My suggestion would be to write your own token like [node:nid-content-type] (because at the point [node:content-type:*] you've lost the node context, and only have the content type itself to use in the token replacements).
If you need help writing your own token, I can point you to documentation for it. The key parts are hook_token_info() to declare the tokens you have to provide, and then hook_tokens() to actually perform the token replacement. Core provides several good examples for adding tokens to nodes, like comment_token_info/comment_tokens.
For the scope of Token module, we can only provide tokens for data that Drupal core itself has available, so marking this as won't fix.