Jon E Posted September 29, 2017 Share Posted September 29, 2017 Hi, Been scratching my head on this one all day - I have a function to find if my current page is referred to in other pages, which is working fine, but I want to only output the section if there is content to go in there, i.e. I wouldn't want to show the 'events' heading or div if there are none. I know this should be quite straightforward but I've been looking at this for a couple of days and stuck on it, so any help would be really great. Thanks so much. <div class="written_list_participant"> <h2>Events</h2> <ul> <?php $fe = $pages->find("contributors=$page, template=event"); // $page is the current page foreach($fe as $e){ echo "<li><a href='{$e->url}'>$e->title</a></li>"; } ?></ul> </div> Link to comment Share on other sites More sharing options...
abdus Posted September 29, 2017 Share Posted September 29, 2017 To check if there's any events involving current contributor, use $fe->count, then with a simple if block, you can decide whether to show the events <?php $fe = $pages->find("contributors=$page, template=event"); // $page is the current page ?> <?php if ($fe->count): // dont show if there arent any events ?> <div class="written_list_participant"> <h2>Events</h2> <ul> <?php foreach ($fe as $e): ?> <li><a href="<?= $e->url ?>"><?= $e->title ?></a></li> <?php endforeach; ?> </ul> </div> <?php endif; ?> 3 Link to comment Share on other sites More sharing options...
Jon E Posted September 29, 2017 Author Share Posted September 29, 2017 Thank you so so much @abdus! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now