Underneath several pages I have a bit that gets random projects:
<footer class="site-footer" role="contentinfo">
<?php if ($page->template() == "project" || $page->template() == "article"):
$featured = $pages->find('projecten')->children()->shuffle()->limit(4); ?>
<div class="random-content container">
<a href="/projecten"><h3 class="random-content-title">Meer projecten</h3></a>
<ul class="collection">
<?php foreach($featured as $project): ?>
<li class="collection-item project">
<a href="<?php echo $project->url() ?>">
<img src="<?= $project->images()->sortBy('sort', 'asc')->first()->thumb(array('width' => 300))->url() ?>" alt="Thumbnail for the project <?= $project->title()->html() ?>" class="project-thumbnail" />
</a>
<h4><?php echo $project->title() ?></h4>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
…
</footer>
However, sometimes, I get this error: Call to a member function thumb() on null
.
Here is the footer and the stack trace. Every project has at least one image, so what could be the reason of the error?
Interestingly, I get thumbnails of 16 random projects on the front page, but this never results in an error.