Hi there,
I have a question that I can’t solve. I would like to show related projects inside a news article. In the panel (backend) you can choose which projects are related to a news article.
It all works fine. Until I don’t link a project inside an news article. Then I get an empty gray area (the place where a project is shown when it is linked). But if no projects are linked, this area should of course not be shown.
It has obbvious something to do whit the if else loop and the counts but I have tried almost every combination (I know, not every). I am also wondering if this is also possible with the topages function. Something like:
<?php $slugs = $page->projectlink()->toPages(); if ($slugs->count() > 0): ?>
This is my code:
<?php $slugs = explode(', ',$page->projectlink()); ?>
<?php if(count($slugs) == 0) : ?>
<!-- do nothing -->
<?php elseif (count($slugs) >= 1) : ?>
<div class="wrapper-small projectlink">
<div class="column-section clearfix spaced-none">
<h5 style="padding-bottom: 1rem; font-weight: 400;">
<?php echo count($slugs) > 1 ? 'Related projects' : 'Related project'; ?>
</h5>
<?php foreach($slugs as $slug){ ?>
<?php if($relatedproject = page($slug)) : ?>
<div class="column two-fifth">
<?php if ($image = $relatedproject->images()->findBy('template', 'cover')) : ?>
<a href="<?= $relatedproject->url() ?>">
<div class="team-member">
<img class="team-pic" src="<?= $image->crop(500, 320)->url() ?>" alt="<?= $image->alt() ?>">
</div>
</div>
</a>
<?php endif ?>
</div>
<?php endif ?>
<?php } ?>
</div>
</div>
<?php endif ?>