WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get Post Thumnbail URL (3 posts)

  1. aminabbasian
    Member
    Posted 4 years ago #

    I have set up post thumbnails as set out in this tutorial.

    http://www.wpbeginner.com/wp-themes/how-to-add-post-thumbnails-in-wordpress/

    I call on the image to show in a post by using
    <?php the_post_thumbnail('my-custom-image'); ?>

    This works great, I would however like this image to be linked so that it opens with fancybox showing the full image size.

    I've tried this code:

    <a rel="fancybox" href="<?php $thumbnail_id=get_the_post_thumbnail($post->ID); preg_match ('/src="(.*)" class/',$thumbnail_id,$link); echo $link[1];
    ?>"><?php the_post_thumbnail('my-custom-image'); ?></a>

    But it only opens the thumbnail when the image is clicked.

    Any tips?

  2. aminabbasian
    Member
    Posted 4 years ago #

    I was able to find a solution to this and it's set out at:

    http://wpcanyon.com/tutorials/how-to-use-the-post-thumbnail-feature-in-wordpress-2-9/

    With the final code for the single.php being:

    <?php
    $thumb = get_the_post_thumbnail($post->ID, $size);
    $pattern= "/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i";
    preg_match($pattern, $thumb, $thePath);
    $theSrc = $thePath[0];
    echo "<a href='$theSrc'>".get_the_post_thumbnail($post->ID,array(640,9999))."</a>";
    ?>
  3. wpcanyon
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.