Forums

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

Home Forums Back End [WORDPRESS] Display thumbnail and link to full image attachment

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

    So I created a Post Type named “textures” and I am trying to display a thumbnail of the texture on the “Textures Page” that will link to it’s full image attachment.
    I have a custom meta box set up using the Image uploader.

    I tried using this code//
    <a href="<?[php] the_attachment_link(); ?>">
    <?php $textures_image = get_post_meta($post->ID, 'textures_image', true);
    echo wp_get_attachment_image($textures_image, 'thumbnail'); ?>
    </a>

    The thumbnails were displayed but when I click the image
    I get this in the address bar instead with no full sized image//
    http://domain.com/textures/Missing%20Attachment

    So I tried to edit this code from
    https://codex.wordpress.org/Function_Reference/the_post_thumbnail//

    <?php
    if ( has_post_thumbnail()) {
    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
    echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
    the_post_thumbnail('thumbnail');
    echo '</a>';
    }
    ?>

    (not knowing what in the world I am actually doing)
    and came up with this//
    <?php
    if ( has_post_thumbnail()) {
    $textures_image = get_post_meta($post->ID, 'textures_image', true);
    echo '<a href="' . $textures_image[0] . '" title="' . the_title_attribute('echo=0') . '" >';
    echo wp_get_attachment_image($textures_image, 'thumbnail');
    echo '</a>';
    }
    ?>

    Please keep in mind that I have absolutely no clue what I’m doing here…

    Any way my question is how can I clean and fix this code to get the thumbnail showing and get the link to work and direct viewers to the full image attachment?

    Please Help.

    #158631
    asiek
    Participant

    So I found a solution.
    At first I wasn’t able to get a featured image metabox working…
    But I found a way and got it working in the end.
    So I used this in my template//
    <?php
    if ( has_post_thumbnail()) {
    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
    echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
    the_post_thumbnail('thumbnail');
    echo '</a>';
    }
    ?>

    &that did the trick :)

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.