Page 1 of 1

Need help building galleries with non-sequential names

Posted: Fri Mar 04, 2011 9:38 pm
by JavaNoob
I'm having trouble figuring out how to build a gallery for a list of wallpapers that, as a whole, don't have sequential naming schemes. One example would be:

image/img1_800.jpg
image/img1_1024.jpg
image/img1_1280.jpg
image/img2_800.jpg
etc.

Other conventions might include (though not simultaneously)

image/img1_800x600.jpg
image/img1_1024X768.jpg
image/img1_1280x1024.jpg (notice the two changing number sets)

as well as,

image/img1_s.jpg
image/img1_m.jpg
image/img1_l.jpg (notice the use of non-sequential letters)

In the past I've had to either build separate galleries for each resolution listed, or make an absolutely crazy large gallery with thousands of invalid links. I'm sure there's a simple solution, but as previously stated, I've zero experience with java. Thank you for you time and patience.

PS - Also, if it's not to much trouble, could you briefly explain why the answer you give works, so that I don't have to ask again if other similar naming schemes show up, and I can just re-tailor it to the task. Thanks again.

Re: Need help building galleries with non-sequential names

Posted: Fri Mar 04, 2011 9:55 pm
by Giorgio Maone
You can use an URL pattern like this:

Code: Select all

http://example.com/image/img[1-10]_[label([0-2], ["800x600","1024x768","1280x1024"])].jpg
After entering it, in the "JavaScript Functions" tab you'll find a new label() function entry.
Define it this way:

Code: Select all

var index = arguments[0];
var types = arguments[1];
return types[index];
This function will allow you to replace numeric indexes (in this case in the range 0-2) passed as the first arguments with arbitrary strings, passed as an array in the second argument (in this case ["800x600","1024x768","1280x1024"]).

Re: Need help building galleries with non-sequential names

Posted: Sat Mar 05, 2011 10:40 am
by JavaNoob
Thank you very much! it worked like a charm. So all I've got to do is change what's in the quotes and/or the number rage, say [0-4] for larger sets?

Re: Need help building galleries with non-sequential names

Posted: Sat Mar 05, 2011 12:59 pm
by Giorgio Maone
JavaNoob wrote:Thank you very much! it worked like a charm. So all I've got to do is change what's in the quotes and/or the number range, say [0-4] for larger sets?
Yes :)