Hi everyone,
I’m a noob… I’m putting together a blog style news section for a client. I can’t work out how to create three loops that are each filtered by a specific tag. There seems to be issues when making subpages invisible and/or using the ‘past-news’ tag to filter. Any advice would be awesome! Thanks.
<h2>Current</h2>
<?php if($articles->count()): ?>
<?php $articles = $page->children()
->visible()
->filterBy('tags', 'current-news', ',') ; ?>
<?php foreach($articles as $article): ?>
<article>
<div class="image-container" style="background-image:url('<?php if($image = $article->image()): ?>
<?php echo $article->image()->url() ?>
<?php endif ?>');"></div>
<div class="container">
<a href="<?= $article->url() ?>"><h1 class="headline"><?= $article->title()->html() ?></h1></a>
<time><?= $article->date('d/m/Y') ?></time>
<p><?= $article->text()->kirbytext()->excerpt(20, 'words') ?> </p>
<a class="read-more" href="<?= $article->url() ?>">Read more</a>
</div>
</article>
<?php endforeach ?>
<?php else: ?>
<p>This blog does not contain any articles yet.</p>
<?php endif ?>
<h2>Future</h2>
<?php if($articles->count()): ?>
<?php $articles = $page->children()
->visible()
->filterBy('tags', 'future-news', ','); ?>
<?php foreach($articles as $article): ?>
<article>
<div class="image-container" style="background-image:url('<?php if($image = $article->image()): ?>
<?php echo $article->image()->url() ?>
<?php endif ?>');"></div>
<div class="container">
<a href="<?= $article->url() ?>"><h1 class="headline"><?= $article->title()->html() ?></h1></a>
<time><?= $article->date('d/m/Y') ?></time>
<p>National sports charity ‘Tennis For Free’ has served up an ace for Watford by investing in a year-long programme of free tennis sessions. </p>
<a class="read-more" href="<?= $article->url() ?>">Read more</a>
</div>
</article>
<?php endforeach ?>
<?php else: ?>
<p>This blog does not contain any articles yet.</p>
<?php endif ?>
<h2>Past</h2>
<?php if($articles->count()): ?>
<?php $articles = $page->children()
->visible()
->filterBy('tags', 'past-news', ','); ?>
<?php foreach($articles as $article): ?>
<article>
<div class="image-container" style="background-image:url('<?php if($image = $article->image()): ?>
<?php echo $article->image()->url() ?>
<?php endif ?>');"></div>
<div class="container">
<a href="<?= $article->url() ?>"><h1 class="headline"><?= $article->title()->html() ?></h1></a>
<time><?= $article->date('d/m/Y') ?></time>
<p>National sports charity ‘Tennis For Free’ has served up an ace for Watford by investing in a year-long programme of free tennis sessions. </p>
<a class="read-more" href="<?= $article->url() ?>">Read more</a>
</div>
</article>
<?php endforeach ?>
<?php else: ?>
<p>This blog does not contain any articles yet.</p>
<?php endif ?>