numbering nodes sequentially by type

joachim - February 13, 2009 - 13:07

I'm sure this is something that's been asked before but I must be entering the wrong search terms of google....

I want to have different content types at sequentially numbered paths, by content type.
This is because I'm migrating a site from a custom script, which has news posts and image posts, each with their own sequence. So what I'd like to get is story nodes to get paths like /story/1, story/2, etc, and images to be image/1, image/2, and so on.

I can see a way to do it with pathauto and token. I'd do it with a custom module that stores a table of nids and sequential ids, and provides a hook for token to use.
-- but has anything like this already been implemented?

Could Apache/PHP/database redirects be a better solution?

frames - February 13, 2009 - 19:06

Not an expert here, but I think what you explain you want to do adds some complexity to the site since you would have to "hook" queries and create a custom module just for that. And that would be only for "part of the site".

Although that would be feasible, why just not freeing Drupal of that work and let Apache do it?

I "recently" read a small post somewhere where a guy was using a simple php script and an also simple text database with pointers like:

story/1|story/why-i-love-drupal
story/2|story/cause-its-cool
image/1|image/picture-one

... or the like.

PHP was doing the redirects. Everytime the server hit a page in the database (on the left above) it would be redirected to the url on the right.

This was not the page I'm talking about, but makes a mention of it: How to redirect old webpages to the new ones. I'm sorry I can't forget where I saw it now. Will post it if I can get ahold of it.

Other way I see still using Drupal only would be importing all your stuff, then populating the tables that path/pathauto/... use. You would have to run as many sql queries as "nodes" you have rigth not, but you would have to do it only once.

There's also a field in each node called "Automatic alias path", but I believe that comes from pathauto. It would be a matter of doing something similar to what I described above (sql inserts).

This might help as well: Redirecting specific pages to new URLs (301 redirects in Drupal). And this set of posts on migration tips from Acquia might also come handy.

If possible, I would avoid Apache mod_rewrite (if you have lots of "old" links or those as in this case do not have a specific pattern), so that you keep the server overhead to a minimum. Oh! And make those redirects 301's so that search engines are aware of the change.

Sorry I'm not being more specific. Like I said, I'm no expert and I didn't look into specific tables in the databases, just seeying if that would make sense for now.

I was going to use path

joachim - February 13, 2009 - 20:40

I was going to use path aliases for the old URLs, or maybe a custom module that implement hook_menu and catches all /old_url_news.script?ID and sends them to something clean like /news/ID.
But I'd like new news nodes to keep following a sequential pattern.
This doesn't mean a query on each page load -- just one query when Pathauto updates the path for the node. The module would provide a token [news_id] for the given nid from its lookup table.
I initially thought it could be done more simply by just giving the count of older nodes of that type -- but that would break if nodes got deleted.

I can see how toimplement it -- just wondering if it's already been done, save me reinventing the wheel :)

I see what you meant now ...

frames - February 13, 2009 - 21:33

Sorry I was not very helpful. I put too much emphasis in the part where you said "This is because I'm migrating a site from a custom script".

You know more than I do regarding Drupal, but I guess you're going after something like: when Pathauto generates the alias, query the database, see how many nodes of that type are already created in the database, then increment by one and pass that number to the alias ... or something along those lines.

I think so

Michelle - February 14, 2009 - 15:38

This may be too vague to be helpful but I'm about 90% sure I've seen a contrib module that does this. It was a long time ago, though, so was likely for D5 or maybe even for 4.7.

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

found

joachim - February 18, 2009 - 18:11

Cool!

Michelle - February 19, 2009 - 04:05

And there's even a D6 version. :)

Michelle

Yup. And the way it's

joachim - February 19, 2009 - 09:19

Yup.
And the way it's implemented is exactly how I was planning to do it!

 
 

Drupal is a registered trademark of Dries Buytaert.