Files public link function?

Hey out there,

actually i create a sponsor site for a sport club. They have about 30-40 sponsors and they would like to have for each sponsor a logo within a link to their website.
I uploaded all logos and put them on the site with php.

<?php foreach($page->images()->sortBy('sort', 'asc') as $image): ?>
 <div class='col-sm-4 col-xs-6 col-md-3 col-lg-3'>
  <a class="thumbnail fancybox" rel="gallery" href="<?php echo $image->url() ?>">
   <?php echo thumb($image, array('width' => 300, 'height' => 200, 'crop' => true)) ?>
  </a>
 </div>
<?php endforeach ?>

There’s no problem. But how can i give each logo the link to their website? Anyone have an idea? :smirk:
Greets
Florian

Hey there,

you could simply use a field in the images. Define it in the blueprint like this:

files:
  fields:
    sponsorlink: 
      label: Link to spnsor
      type:  url

And then simply echo it in the foreach:

<?php foreach($page->images()->sortBy('sort', 'asc') as $image): ?>
 <div>
  <a href="<?php echo $image->sponsorlink() ?>">
   <?php echo thumb($image, array('width' => 300, 'height' => 200, 'crop' => true)) ?>
  </a>
 </div>
<?php endforeach ?>

Have fun,
Thomas

1 Like

@thguenther Thanks :)) worked