Getting a conditional message out of a foreach loop
I'm displaying all the posts in the category that have a valid date as
follows -
<?php $blog = $pages->find('posts');
foreach($blog->children() as $blogpost): ?>
<?php if ($blogpost->title() <= $latest && $blogpost->category ==
$thisCat): ?>
//HTML for displaying post goes here
<?php endif ?>
<?php end foreach ?>
That works fine when those posts validate my condition, and displays
nothing if it doesn't. What I want to do is display an error message (like
'there are no posts here') when there are no posts that pass the
condition. I can't just do a simple else condition in that if query
because it's inside the foreach loop. I can't take the if query out of the
foreach loop because it relies on a variable that is defined as part of it
($blogpost).
Kind of stuck in this catch 22... Any suggestions?
No comments:
Post a Comment