Jump to content

Larger image from Thumbnail


buster808
 Share

Recommended Posts

Hi,

I have used a simple loop to show images in my template. How can I get this to link to a larger image possibly in a lightbox with arrows?

Thanks

foreach ($page->images as $image) {
        $content .= "<img src='{$image->url}'/>";
}
Link to comment
Share on other sites

got this working

 

foreach ($page->images as $image) {
 
        $content .= "<div uk-lightbox>";
        $content .= " <a href='{$image->url}'><img src='{$image->url}'/></a>";
        $content .= "</div>";
}
Link to comment
Share on other sites

<div uk-lightbox>
<?php foreach($page->images as $image): ?>
<a href="<?php echo $image->url; ?>" data-alt="<?php echo $image->description; ?>">
    <img src="<?php echo $image->width(120)->url; ?>" alt="<?php echo $image->description; ?>">
</a>
<?php endforeach; ?>
</div>

I'd go this way. The first DIV shouldn't be in the foreach() loop.

You also want to take a closer look at the different output strategies ProcessWire provides. You are using the delayed output method which can be confusing for beginners. Look at the direct output strategy instead. That's where my example came from.

https://processwire.com/docs/front-end/output/

  • Like 1
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...