I think this will be quick for someone but if it's not, please say so and I will up the bounty.

I am using heimstein's little module http://drupal.org/node/101748#comment-207307 so that teaser images show up in my product listings, but the teaser image links to the regular size image:

$image_tag = ''
    .'<a target="_blank" href="'.$image_regular.'" >'
        .'<img src="'.($image_teaser).'" >'
    .'</a>' 

and what I want is for it to link to the full node.

I am using Views for the product listings and have the Node title option As Link so it links to the Node. I tried adding a Field Node: Link to node, which adds a link to the node too, but not on the teaser image. The link could be on the Node body (if that option was there) because all my product nodes are set up with the image, then !--break--, then the description.

Can either the teaser_images.module code or the view code be changed to do what I want?

Please email me with a solution (and post it here too in case anyone else wants to use it) and I will pay $25 CDN by PayPal.
Thank you

Comments

marie70’s picture

Thank you Amit for finding this solution for me. Here is the code, replace the teaser_images.module file with this and the teaser image will link to the full node:

// $Id: teaser_images.module,v 2.0 2007/02/28 19:26:22 heimstein Exp $

function teaser_images_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Converts images in teasers into thumbnails.');
    case 'node/add#teaser_images':
      return t('Converts images in teasers into thumbnails.');
    case 'admin/settings/teaser_images':
      return t('Converts images in teasers into thumbnails.');
  }
}

function teaser_images_nodeapi(&$node, $op, $teaser, $page) {
$host = "http://". $_SERVER['HTTP_HOST'] . "/";

  switch ($op) {
    case 'alter':
          $find = '/<img(.+?)>/i';
          $teaser = preg_replace_callback($find, "teaser_images_replace", $node->teaser);
          $teaser = str_replace("||<||",'<a href="'.$host.'node/'.$node->nid.'" title="'.$node->title.'" >',$teaser);
          $teaser = str_replace("||>||",'</a>',$teaser);
          $node->teaser = "".$teaser;
    break;
  }
}

function teaser_images_replace($image) {
  $image = $image[1];
  $find= '/src="(.+?)"/i';
  preg_match($find, $image, $matches);
  $image_regular = $matches[1];
  $parts = explode(".",$matches[1]);
  $parts[count($parts)-1] = 'teaser.'.$parts[count($parts)-1];
  $image_teaser = implode(".",$parts);
  $image_tag = ''
    .'||<||'
        .'<img src="'.($image_teaser).'" >'
     .'||>||'
  ;
  if(!file_exists($_SERVER['DOCUMENT_ROOT'].$image_teaser)) {
    image_scale(
        $_SERVER['DOCUMENT_ROOT'].$image_regular,
        $_SERVER['DOCUMENT_ROOT'].$image_teaser,
        100, 100
    );
  }
  return $image_tag;
}
basicmagic.net’s picture

comment

Drupal samurai for hire, based in Buffalo, New York, USA.
15+ years Drupal, 20+ years web.
http://basicmagic.net