Support

Account

Home Forums General Issues Image link to attachment page

Solving

Image link to attachment page

  • Hi everyone,

    I would like to know if it’s possible to set up a link on the image field to the attachment page?
    I can do it if I choose the Wysiwyg Editor to publish some images. (link to: attachment page) but it’s really not convenient…

    Thanks in advance,
    best

  • Yeah, thanks, I saw that but it still isn’t working, it sends me to the current page…

    I don’t know how to write the code right.
    Here’s my code and I want to go the attachment page (the single page). Do you have an idea what can I do?
    Thank you very much`

    <?php 
    
    $images = get_field('galerie_bd');
    
    if( $images ): ?>
    <ul class="rslides">
            <?php foreach( $images as $image ): ?>
                <li>
                    <a href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['url']; ? />" />
                    </a>
                                </li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
  • You’re going to need to alter the field so that it returns the attachment ID instead of the URL. For more information see WP doc for the functions I use here.

    
    <?php 
    
    $images = get_field('galerie_bd');
    
    if( $images ): ?>
    <ul class="rslides">
            <?php foreach( $images as $image ): ?>
                <li>
                    <a href="<?php echo get_attachment_link($image); ?>">
                         <?php 
                             $size = 'thumbnail';
                             $attach = wp_get_attachment_image_src($image, $size);
                         ?>
                         <img src="<?php echo $attach[0]; ? />" />
                    </a>
                                </li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    
  • Thank you for your answer but the image doesn’t appear now and the link is related to an different article…
    Do you know why?
    I’m sorry but I’m a little bit slow to understand the functioning of all this.

  • make sure you’re trying to get an image size that is set up on your site. Other than than you’ll need to do some debugging, it should be working so I can’t really help you past this point without knowing why it’s not working.

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

You must be logged in to reply to this topic.