I using @texnixe related pages plugin but i want to hide some code unless related pages actually exist, otherwise I will end up with a useless heading and a dead list.
Heres my snippet:
<?php
$relatedPages = $page->related(array(
'searchCollection' => $site->index()->find('blog')->children()->visible(),
'searchField' => 'tags',
'matches' => 2,
'delimiter' => ','
));
?>
<!-- only if related pages exist -->
<div class="blog-similar flank">
<header>
<h2>Similar Articles</h2>
</header>
<ul>
<?php foreach($relatedPages as $related): ?>
<li><p><a title="<?= $related->title() ?>" href="<?= $related->url() ?>"><?= $related->title() ?></a></p></li>
<?php endforeach ?>
</ul>
</div>
<!-- end only if related pages exist -->
I don’t know how to check the $relatedPages
for a positive match on related articles. I don’t think isset
will work because from var_dump
it always gets a value, but i’m no genius
Whats the best way please?