I’m creating a website for a publication and they would like to take some articles from their blog and feature it on their homepage. I have a feature toggle installed on an article blueprint and then created a snippet I attach to the home.php that looks for if the toggle is on and limited it to breaking after it finds three. The only issue is that it starts from the articles from oldest to most recent. Is there any easy way to change this? Can I start the foreach loop from the most recent?
Here is my code:
Snippets/Feature.php
<?php
$blog = page('archive')->children();
$counter = 0;
foreach($blog as $articles) : ?>
<?php if($articles->feature() == 'yes') {
$counter++;
?>
<article class="article index" >
<header class="article-header">
<div class="ftimg">
<a href="<?= $articles->url() ?>">
<?php echo $articles->featureimage()->toFile() ?>
</a>
</div>
<h2 class="article-title">
<a href="<?= $articles->url() ?>"><?= $articles->title()->html() ?></a>
</h2>
<h3 class="article-subtitle"> <?= $articles->subtitle()->html() ?></h3>
<div class="article-details">
<h4 class="article-author"> <?= $articles->author()->html() ?> —</h4>
<p class="article-date"∂><?= $articles->date('F jS, Y') ?></p>
</div>
</header>
</article>
<?php if($counter == 3) break; } else {
}
?>
<?php endforeach ?>