Exclude main project image from project page

I have a list of projects on my homepage that display only the picture titled ‘home-page.jpg’

<?php if($image = $project->image('home-page.jpg')): ?>
    <img src="<?php echo $image->url() ?>" alt="<?php echo $project->title()->html() ?>">
<?php endif ?>

I want to exclude that picture from being visible on the actual project page. At the moment I have:

<?php foreach($page->images()->sortBy('sort', 'asc') as $image): ?>
    <figure>
      <img src="<?php echo $image->url() ?>" alt="<?php echo $page->title()->html() ?>">
    </figure>
<?php endforeach ?>

And this brings in ‘home-page.jpg’ but I only want that visible on the home page

Have a look at the filter methods on file collections: http://getkirby.com/docs/cheatsheet/files/filterBy

<?php foreach($page->images()->filterBy('filename', '!=', 'home-page.jpg')->sortBy('sort', 'asc') as $image): ?>
    <figure>
        <img src="<?php echo $image->url() ?>" alt="<?php echo $page->title()->html() ?>">
    </figure>
<?php endforeach ?>

You can also create custom filter methods, if you need anything else: http://getkirby.com/docs/advanced/filter-methods

1 Like

Great thanks I’ll take a look at the docs and see if I can get my head around it.