• Resolved paa1605

    (@paa1605)


    Hey folks,

    I need your expert help in trying to solve a WordPress problem of mine. Basically, i’m designing a shopping site where products are posts. On the home page there is a best selling section with 4 or 5 thumbnails and excerpts to some of the best selling products. These are inside divs acting as links which when clicked take the user to the individual product page. What i’ve done is utilise the new features of WordPress and added the ‘post-thumbnails’ theme support so that when i add a new product as a post i can use the ‘featured image’ option and WordPress will automatically size the photo i upload to my required measurements on the thumbnails found on the homepage and the main image on the individual product page.

    What i am trying to do is have the image on the product page as a link so that when the user clicks on it they will see the image in its original, large size. How is this possible???

    Currently the image is called using the following code:

    <div class=”image-main”>

    <?php the_post_thumbnail(‘single-post-thumbnail’); ?>

    </div>

    Any help would be greatly appreciated. Thanks in advance,
    Patrick.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    try this inside the loop:

    <div class="image-main">
    <?php
     if ( has_post_thumbnail()) {
       $post_thumbnail_id = get_post_thumbnail_id();
       $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
       echo '<a href="' . $post_thumbnail_url . '" >';
       the_post_thumbnail('single-post-thumbnail');
       echo '</a>';
     }
    ?>
    </div
    Thread Starter paa1605

    (@paa1605)

    Thanks very much, it worked perfectly!!

    I sort of understand the code but i would never have come up with that myself. Many, many thanks!

    Patrick

    Thread Starter paa1605

    (@paa1605)

    Sorry i just have one more question, how do i get the now linked image to appear in a new window when clicked on? I know the usual thing is to insert target=”_blank” into the code but where should it be placed in this example? Thanks for your time.

    Moderator keesiemeijer

    (@keesiemeijer)

    you put it in the link like this:
    echo '<a href="' . $post_thumbnail_url . '" target="_blank">';

    Thread Starter paa1605

    (@paa1605)

    Awesome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Help Needed!! – Post Thumbnails With Links’ is closed to new replies.