Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-07 15:26:14

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

sort numerically named sections despite lack of leading zeros?

I’ve got a bunch of sections which have been named like: thing1, thing2, thing3 … thing9, thing10, thing11.

I want to do txp:article_custom with sort=“section desc” and of course the lack of leading zeros is making them show up in the “wrong” order: thing1, thing10, thing11, thing2, thing3, etc.

Renaming the sections would be bad because there are plenty of links to URLs that include the section names. (Though if need be, I could use .htaccess to redirect.)

Any suggestions on the best solution for this?

Offline

#2 2011-06-07 15:42:03

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: sort numerically named sections despite lack of leading zeros?

If ‘thing’ is the same for all sections and is 5 characters long, then try sorting like this sort="SUBSTR(section,6)+0". The SUBSTR returns all characters from the section name starting on position 6 and the +0 converts the string into a number to make sorting work.

Offline

#3 2011-06-07 17:39:47

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

Re: sort numerically named sections despite lack of leading zeros?

Worked perfectly—thanks, Ruud!!!

Offline

Board footer

Powered by FluxBB