Get X latest created images located anywhere inside a specific folder in Media?
Hi!
I want to display the 10 (or any number) latest created images located anywhere inside a specific folder in Media. As input i have the ID of the folder in which the images are located and a number for how many images to get. The tricky part is not getting the images if they are located directly in the selected media folder, but getting them if they are somewhere deep down in a nested subfolder. I think some form of recursion is needed but I find it difficult to wrap my head around both recursion and sorting on createDate at the same time.
You're pretty close, actually - the key is getting all the descendant images - that's what the double-slash does - otherwise you we're cool; my changes are pretty much just semantics:
Get X latest created images located anywhere inside a specific folder in Media?
Hi!
I want to display the 10 (or any number) latest created images located anywhere inside a specific folder in Media. As input i have the ID of the folder in which the images are located and a number for how many images to get. The tricky part is not getting the images if they are located directly in the selected media folder, but getting them if they are somewhere deep down in a nested subfolder. I think some form of recursion is needed but I find it difficult to wrap my head around both recursion and sorting on createDate at the same time.
The XSLT I have so far looks like this:
Is it possible to do what I'm trying to do with XSLT and if so, what would it look like?
Thanks in advance!
/Thomas Kahn
Hi Thomas,
You're pretty close, actually - the key is getting all the descendant images - that's what the double-slash does - otherwise you we're cool; my changes are pretty much just semantics:
/Chriztian
Wow! Thanks Chriztian!
I had no idea I could use the double slash like this when working with the media section.
Just one modification to the script - just a syntax thing ($numberOfItems need to be interpreted as a number):
Thanks a million! Your answer saved me a lot of headaches and frustration!
No problem!
I've never had to use the number() function for situations like that - curious if you were having problems without it?
XSLT usually does the conversion that makes most sense... (since everything in XML is a string...)
/Chriztian
Yes, I was getting an error if I omitted the number() function. It must be because the value comes from a macro parameter which is a string.
Hehe - I'm willing to bet you a beer that there's an accidental extra space in that macro parameter then :-)
Nevermind - it works! On to the next problem :-)
/Chriztian
is working on a reply...