Sorting images by modified date?

Hi,

I’m trying to set up a gallery using the following folder structure:

/content
    /01-project_a
        /01-album_a
        	image1.jpg
        	image1.jpg.txt
        	image2.jpg
        	image2.jpg.txt
        /02-album_b
        	image1.jpg
        	image1.jpg.txt
        	image2.jpg
        	image2.jpg.txt
        	image3.jpg
        	image3.jpg.txt
    /02-project_b

The main goal is to grab all images from album_a and album_b and sort them by the date they’ve been uploaded/edited. Is this even possible to achieve? Using something like

<?php foreach($page->children()->images()->sortBy('modified', 'desc') as $picture): ?>

always causes a fatal error. What would I have to do to achieve this?

Thanks in advance for your help.

WARNING: I’m a newbie, so this answer is based on reading the docs, rather than on experience!

According to the docs, the children() method returns a $pages collection object.

The images() method is available to single $page objects, not $pages collections.

You may have to build your images list in two steps:

  1. Use $page->children() to gather a list of your relevant pages
  2. Manually build a list of images for all pages by iterating through each page

I hope this helps!