I have images pulling into site but it seems to be pulling them based on most recent added, is there any way to pull by file name alphabetically?
I'm not too experienced with CF but I am good with HTML/CSS trying to fix some things on a friends site due to a runaway backend developer.
sorry if this doesn't make too much sense.
this is what it currently looks like
<img width="920" height="300" src="data/images/<cfoutput>#ListGetAt(pic, 1)#</cfoutput>" />
<img width="920" height="300" src="data/images/<cfoutput>#ListGetAt(pic, 2)#</cfoutput>" />
Copy link to clipboard
Before you start using your list, convert it to an array using ListToArray(), then do an ArraySort() on it. I'd also consider replacing your code with a loop that loops over your list or array and adds the <div> and <img> elements. Then you can accommodate any number of pictures in a more dynamic fashion.
<cfset PicArray = ArraySort( ListToArray( pic ), "text", "asc")>
<cfloop array="#PicArray#" index="ThisPic">
<img width="920" height="300" src="data/images/#ThisPic# />
If the picture names have upper and lower case characters, and you want case insensitive sorting, just change "text" to "textnocase" in line 1 above.
Thank you Carl, I think I might have gotten it to work using
getlistat(ListSort(pic, "textnocase"), 1)
Im testing it now, if it doesn't work I will try your method
I am not a backend developer so the least I need to do here the safer I will feel
For some reason I completely forgot about ListSort(). Maybe because there have been issues in the past with handling empty list items (arrays had no problems with empty items).
Anyway, what you have will work. I'd still consider modifying your code to use a loop as it will be more flexible and maintainable. It is not clear from your code how many pictures are actually in the list (always 2, 2 or more, etc.), so a loop will handle all the possibilities without a bunch of repeating code.