Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Display image as link if URL is added to custom field for CPT

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #151927
    asiek
    Participant

    I have a custom post type named “Overlays”, and 2 custom fields: One with an image uploader, another with a text area to add a URL to the zip file for viewers to download.

    At first the issue was finding a code to display the anchor tags only if an URL was added, and if not URL is found then only display the image. I found a solution for that which is//

    <?php
    $overlays_dll = get_post_meta($post->ID, 'overlays_dll', true);
    if ( $overlays_dll ) {
     echo '<a href="';
     echo $overlays_dll;
     echo '">';
     echo $overlays_image = get_post_meta($post->ID, 'overlays_image', true);
     echo wp_get_attachment_image($overlays_image, 'full');
     echo '</a>';
    }
    else {
     echo $overlays_image = get_post_meta($post->ID, 'overlays_image', true);
     echo wp_get_attachment_image($overlays_image, 'full');
    }
    ?>
    

    It works how I would like it to only with one small issue…on the front-end of my site numbers from 200-400 appear on the bottom left of most of the images… I’m not sure how to fix this, clearly…lol

    Can anyone help me remove these measly numbers? -Keisa

    #151937
    asiek
    Participant

    ////////// S O L V E D \\\
    All I had to do was remove the echo from a couple lines and now the numbers are gone :)

    My new code//

    <?php
    $overlays_dll = get_post_meta($post->ID, 'overlays_dll', true);
    
    if ( $overlays_dll ) {
     echo '<a href="';
     echo $overlays_dll;
     echo '">';
     $overlays_image = get_post_meta($post->ID, 'overlays_image', true);
     echo wp_get_attachment_image($overlays_image, 'full');
     echo '</a>';
    }
    else {
     $overlays_image = get_post_meta($post->ID, 'overlays_image', true);
     echo wp_get_attachment_image($overlays_image, 'full');
    }
    ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.