Create unique IDs for nodes within specific content type in Drupal 7

While modifying this site I got a simple need - to create urls with unique numbers for each node of certain content type, e.g.: links/1, links/2, links/3 etc. By default Drupal provides each node with unique global NID (node-ID) which goes through all content types of the site, so you can have blog entry with NID 1, then link with NID 2, then news item with NID 3, again blog entry with NID 4 etc. Creating urls for specific content type based on NIDs will make them look as if some parts of content were lost. While the idea of IDs per content type was so simple and obvious, I had to spend pretty long time searching. I was sure "there is a module for this", and right when I was about to give up and post a question on support forum, I finally found it - Serial Field. It provides a field which auto increments, so just add it to content type - and there it is, unique id. This id can be used for automated path aliases creation with Path Auto.

Tip: after adding serial field to content type do not change its settings in "Manage display" tab. By default they are: Label - above, Format - Default. Don't change them or PathAuto will stop generating urls using this field.

There is also another module with similar functionality Type-local nids, but I haven't tried it as there is no stable Drupal 7 release and module seems to be abandoned.

 

---

Originally published on the previous version of my website.