Jump to content

Check if $pages->find


Jon E
 Share

Recommended Posts

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

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; ?>

 

  • Like 3
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...