Support

Account

Home Forums General Issues Image clickable

Solved

Image clickable

  • Hi all,

    First of all, thank you for reading this.
    I am using ACF in order to show data of movies (well, nothing new).
    Here is an example for now on the website :
    http://avisdupublic.net/critique/film/science-fiction/critique-iron-man-3/(test case)
    My issue is concerning the image. I would like it to be opened in alightbox pop-up via a click (as in the case in the content) (with the valenti theme, the code to obtain this is < a class=”cb-lightbox etc ….>).

    However, I am a real noob in code.
    For now, here is my PHP code :

    <?php 
    
    $image = get_field('image');
    $size = 'cb-480-240'; // (thumbnail, medium, large, full or custom size)
    
    if( $image ) {
    
    	echo wp_get_attachment_image( $image, $size );
    
    }
    ?>

    So here, I am stuck. I really don’t know where to put the linking part and how to do this. If someone could help me, I’ll be glad.

    Thanks in advance.

  • I don’t know anything about the popup in that theme, I’m assuming that you are supposed to link to a larger size image, so you’ll need to get both sizes. Your code should probably look something like this.

    
    $image = get_field('image');
    $small_size = 'cb-480-240'; // (thumbnail, medium, large, full or custom size)
    $large_size = 'full';
    
    if ($image) {
        $small_image = wp_get_attachment_image($image, $small_size);
        $large_image = wp_get_attachment_image_src($image, $large_size);
        ?>
            <a class=”cb-lightbox" href="<?php echo $large_image[0]; ?>
                <?php echo $small_image; ?>
            </a>
        <?php 
    }
    
  • Hi John,

    Thanx you helped me a lot. Well, PHP seems quite logical, you say this_is_my_variable and now I play with.

    Actually, I changed a small part of your code because some end balise were missing.
    I put below my working code.

    With my best thanks.

    Z

    `<?php
    $image = get_field(‘image’);
    $small_size = ‘cb-480-240’; // (thumbnail, medium, large, full or custom size)
    $large_size = ‘full’;

    if ($image) {
    $small_image = wp_get_attachment_image($image, $small_size);
    $large_image = wp_get_attachment_image_src($image, $large_size);
    ?>
    “>
    <?php echo $small_image; ?>

    <?php
    }
    ?>’

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

The topic ‘Image clickable’ is closed to new replies.