0

Hi I've been working with Kirby. I'm a complete beginner in PHP but managed to get a lot done. Just need some help with the gallery.

On the homepage a single image is displayed as thumbnail:

<?php foreach($articles as $article): ?>
    <li class="<?php foreach(str::split($article->tags()) as $tag): ?><?php echo $tag ?> <?php endforeach ?>">
    <a href="<?php echo $article->url() ?>" title="<?php echo html($article->title()) ?>"><?php foreach($article->images() as $image): ?><?php echo thumb($image, array('width' => 300, 'quality' => 70)) ?><?php endforeach ?><p><?php echo html($article->title()) ?></p></a>
    </li>             
<?php endforeach ?>  

On the article page I'd like to have a gallery. The gallery snippet:

<?php if($page->hasImages()): ?>
    <ul class="gallery">
        <?php foreach($page->images() as $image): ?>
           <li>
           <a href="<?php echo $image->url() ?>"><img src="<?php echo $image->url() ?>" width="<?php echo $image->width() ?>" height="<?php echo $image->height() ?>" alt="<?php echo $image->name() ?>" /></a> 
           </li>
        <?php endforeach ?>
    </ul>
<?php endif ?>

Using Kirby, makes me store all the article items in one folder. But if I do this, and use the code mentioned above, all the images from the gallery also show up as thumbnails on the homepage. I guess the best would be to edit the gallery snippet so it can grab images from a subfolder. But how?

Thank you for your help!

2 Answers2

0

One solution to this is to name the file you wanna have displayed on the front page something like front.jpg. You can then directly access this image with $page->images()->find('front.jpg').

So you get this:

<?php foreach($articles as $article): ?>
  <li class="<?php foreach(str::split($article->tags()) as $tag): ?><?php echo $tag ?> <?php endforeach ?>">
  <a href="<?php echo $article->url() ?>" title="<?php echo html($article->title()) ?>">
    <?php echo thumb($article->images()->find('front.jpg'), array('width' => 300, 'quality' => 70)) ?>
    <p><?php echo html($article->title()) ?></p>
  </a>
  </li>             
<?php endforeach ?>

(Note, that you have to remove the inner foreach-loop, because you're only displaying one image.)

The gallery snippet stays the same.

lulezi
  • 831
  • 7
  • 15
0

Here try:

       <?php foreach($page->image()->yaml() as $image): ?>
       <?php if($img = $page->image($image)): ?>

        <img src="<?= $img->url() ?>" alt="<?= $page->title()->html() ?>" width="100%" height="100%" />
      <?php endif ?>
    <?php endforeach ?>