Overriding filename sorting for images

I’ve got a page with several images, namely davlstudio.com/home/coolhouse-bouw-update. The images on this page appear in order of their filename:

        <? if($page->hasImages()): 
            foreach ($page->images() as $image): ?>
            <a href="<?= $image->url(); ?>" data-caption="<?= $image->alt()->html(); ?>" class="article-image-link">
                <figure class="article-image">
                    <?= $image->thumb(array('width' => 600)); ?>
                </figure>
            </a>
            <?php endforeach; ?>

this is the full template

However I applied manual sorting to the images: screenshot.

So why does Coolhouse_update_6.jpg not appear first on the page?

You have to tell Kirby to sort them by that sort order then:

$images = page->images()->sortBy('sort', 'asc');

If you sort images manually in the Panel, a meta data file with a sort field is created.

Ah, right, I thought the manual sorting would override other sorting. Is there a way to sort by sorting and use filename as a fallback, or is that the default already?

If the files are not sorted manually, Kirby falls back to the default by order in the file system.

1 Like

Thank you, this solved my issue!