Home Forums Add-ons Gallery Field Linking from the Gallery field to a page


Linking from the Gallery field to a page

    • kwebbin

    • November 27, 2013 at 10:06 pm


    So i have a gallery field setup with some images in them. I want those images to be links to other pages on my site.

    I made a new custom field group called link to add a custom link field for my images in the edit screen. The custom field shows up and shows me the pages i can link to. So far so good. But for some reason the links to other pages don’t work and when i look into the source code it says <a href=""
    I used the <?php the_field(‘link’); ?> code in my template but this is not working. I placed the code like this:

    <div class="opdrachtgevers">
    			<?php $images = get_field('opdrachtgever'); if( $images ): ?>
                <?php foreach( $images as $image ): ?>
                <a href="<?php the_field('link'); ?>" rel="gallery" title="<?php echo $image['title']; ?>" alt="<?php echo $image['title']; ?> <?php echo $image['caption']; ?>"><img src="<?php echo $image['url']; ?>"/>
                  <?php echo $image['caption']; ?>
                <?php endforeach; ?>
                <?php endif; ?>

    I also tried using the get_field code but that doesn’t work either.
    Am i using the code in the wrong way? I’m not that into php coding.


    • Elliot

    • November 28, 2013 at 10:08 am

    Hi @kwebbin

    So close! All you need to do is target the attachment when using the_field(‘link’) like this:

    <a href="<?php the_field('link', $image['id']); ?>"


    • kwebbin

    • November 28, 2013 at 6:41 pm

    Great! Thanks alot Elliot, saved me alot of headaches!

  • Hey there,

    Just a quick question, how do I link each image in a gallery to a different page?

    Kind regards

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.