Linking thumbnail to full size image

I use a function in my blog (getImage) to call thumbnails in the loop (it calls the 1st image on the post) but instead of link to the post, i would want the thumbnail to link to its full image src.

The function is this one:

Read More
function getImages($num) {
global $more;
$more = 1;
$link = get_permalink(); -> NO IDEA IF HAS ANY SENSE BUT I ALREADY TRIED TO CHANGE THIS ONE TO GET_ATTACHMENT BUT NO LUCK
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '/width="150"/',$postOutput);
$postOutput = preg_replace('/alignright/', 'aligncenter',$postOutput);
$image[$i] = $postOutput;
}
if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
$more = 0;}

Does anyone has some clue how can i do this? or other function to achieve this?

Thanks

Related posts

Leave a Reply

2 comments

  1. Oh sure, so here is what i did:
    I added this other function

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
    
      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/default.jpg";
      }
      return $first_img;
    }
    

    And I call it at the $link line, in the getimages function.

    $link = catch_that_image();
    

    Well is messy so i will try your suggestions and see if any of those will work, thanks a lot.