Sort Showcase Snippet thumbnails by descending date

I am attempting to switch the order of my showcase thumbnails on my homepage from the default ascending order. On load, I would like it to display the thumbs on desc order.
I have implemented Isotope filters to add more filtering options if the user would like to see the content differently, but on load it must default to descending.

So far I have referenced the docs on sortBy() and added ‘desc’ in place of ‘asc’ but the page still loads with the same order, showing the first page I ever added as the first thumb. Is there something else I need to add in order to get it to be descending?

here is my showcase snippet:

  <li class="showcase-item column">
    <a href="<?= $project->url() ?>" class="showcase-link">
      <?php if($image = $project->images()->sortBy('date', 'desc')->first()): $thumb = $image->crop(600, 600); ?>
        <img src="<?= $thumb->url() ?>" alt="Thumbnail for <?= $project->title()->html() ?>" class="showcase-image" />
      <?php endif ?>
      <div class="showcase-caption">
        <h3 class="name showcase-title"><?= $project->title()->html() ?></h3>
        <h4 class="tags"><?= $project->tags()->html() ?></h4>
      </div>
    </a>
</li>

url: http://new.readthewhitepaper.com

You are sorting the images by date, but they don’t have a date field to sort by, only the sort field (or their filename).

If you want to change the order of the projects, you have to do that further up in the code where the projects are fetched.

Currently, it looks like this:

$projects = page('projects')->children()->visible();

Change that to

$projects = page('projects')->children()->visible()->sortBy('date', 'desc');

and leave the code for the project images untouched.

1 Like