Clickable imagecache thumbnails?

Lostmonkey - May 15, 2007 - 08:33
Project:ImageField
Version:5.x-2.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,

I hope this is the right place for this request.

I am making a gallery using CCK + Imagefield + Imagecache + Views, but I can't figure out how to the thumbnails link to the image node.

I use views to generate gallery pages based on taxonomy, and would then like these thumbnails to be clickable, however in views the only options for displaying the image are 'Default' and 'Thumb'. Would it be possible to also have a 'Thumb with link to node' option?

Thanks,
Mikkel

#1

NaX - May 18, 2007 - 11:11
Status:active» needs review

I also needed the imagecache images in my views to be clickable to the node. So I did some hacking.
It took me a while because I don’t really know exactly how CCK works with views, but I found a way to do it.

What this does is it adds a duplicate field option for each imagecache namespace to your view field options.
EG.
my_thumb
my_thumb, with node link

If somebody gave this a little love they could maybe do it in a better way and create a patch to a much needed feature.

Please note I had to clear my cache and refresh my view many times before the new option appeared in the dropdown.

See from line 552 in your imagefield.module file. (imagefield.module,v 1.30.2.7)

<?php
/**
* Implementation of hook_field_formatter_info().
*/
define('IMAGECACHE_LINK_OPTION', ', with node link');
function
imagefield_field_formatter_info() {
 
$formatters = array(
   
'default' => array(
     
'label' => 'Default',
     
'field types' => array('image'),
    ),
  );
  if (
module_exists('imagecache')) {
   
$rules = _imagecache_get_presets();
    foreach (
$rules as $ruleid => $rulename) {
      
$formatters[$rulename] = array(
        
'label' => $rulename,
        
'field types' => array('image'),
         );
      
$formatters[$rulename . IMAGECACHE_LINK_OPTION] = array(
        
'label' => $rulename . IMAGECACHE_LINK_OPTION,
        
'field types' => array('image'),
         );
    }
  }
  return
$formatters;
}

/**
* Implementation of hook_field_formatter().
*
*/
function imagefield_field_formatter($field, $item, $formatter) {
  if (!isset(
$item['fid'])) {
    return
'';
  }

 
$file = _imagefield_file_load($item['fid']);
  if (
module_exists('imagecache')) {
   
$node_link = FALSE;
    if (
strpos($formatter, IMAGECACHE_LINK_OPTION) != FAlSE) {
     
$node_link = TRUE;
     
$formatter = str_replace(IMAGECACHE_LINK_OPTION, '', $formatter);
    }
   
   
$rules = _imagecache_get_presets();
    if (
in_array($formatter, (array) $rules)) {
     
$image = theme('imagecache', $formatter, $file['filepath'], $item['alt'], $item['title']);
      if (
$node_link) {
        return
l($image, 'node/'. $file['nid'], array('title' => $item['title']), NULL, NULL, FALSE, TRUE);
      }
      else {
        return
$image;
      }
    }
  }
  return
theme('imagefield_image', $file, $item['alt'], $item['title']);
}
?>

Hope somebody finds this useful.

#2

quicksketch - May 18, 2007 - 13:08

I think you re-implemented something that already exists. Try the latest dev version (though I thought it was in 1.1). This "as link" formatter already exists for every imagecache preset.

#3

NaX - May 18, 2007 - 16:04
Category:feature request» support request
Status:needs review» active

Thanks.

You are correct. I upgraded to the dev version of the imagefield and imagecache and now the as link formatter is there, no problem.

The only thing that confused me for a while was what format / display setting was used for what.

EG.
If you create a view as a table list then it use the value set in the view fields section.
If you create a view as a teaser list then it use the value set in the CCK Display fields section.

I think this is incorrect as you should be able to create multiple teaser views of the same node type with different display settings. IE views display settings should override CCK display settings.

My only Question now is. Are the DEV version of imagefield and imagecache stable for production use and how far are we from the next stable release.

#4

quicksketch - May 18, 2007 - 20:54

The problems you describe all deal with views or CCK, not imagefield directly. The 1.x dev versions of both imagefield and imagecache are reasonably stable and could be used for production and switch back to 1.2 when it's released. Most of the new features (and bugs) are going into the 2.x releases, which I wouldn't recommend for production use.

#5

NaX - May 20, 2007 - 20:53

@ quicksketch
I understand that the problem with the display settings is with CCK and Views. Do you know if those projects are aware of the problem? Would you suggest that I submit an issue about the problem?

Once you have read this and / or replied you can close this issue, unless you want to leave it open for the user the posted the issue.

Thanks for the help.

#6

joshk - July 25, 2007 - 23:38
Version:5.x-1.1» 5.x-2.x-dev

I was unable to find this in either development release. The relevant code appears as follows:

<?php
function imagefield_field_formatter_info() {
 
$formatters = array(
   
'default' => array(
     
'label' => 'Default',
     
'field types' => array('image'),
    ),
  );
  return
$formatters;
}
?>

I'm trying to build a view with clickable images, which is a pretty basic use case. Let me know if/where a patch might be welcome.

#7

j0k3z - July 26, 2007 - 00:49

So is this possible now? Its really annoying to have a thumnail in the view table that cant be clicked

#8

verlierer - August 1, 2007 - 14:18

I've made the items clickable by doing the following: (even with the "image as link" option in views the thumbnails weren't clickable because I'm also using Content Templates.)

In the content template I used the "read more" variable as the href for the image. like this:

<?php
foreach((array)$field_myimagefield_image as $item) {
print
'<a href="'.$node->links['node_read_more']['href'].'"/><img src="'.$item['filepath'].'" title="'.$item['title'].'" alt="'.$item['alt'].'"></a>';
}
?>

Kind of an odd way to do it, but it is working well... thought it might help somebody

#9

deanosrs - August 7, 2007 - 17:07

So with the "as link" we can link to the node that the image belongs to - but is there a way to just link to the actual image?

#10

catch - September 6, 2007 - 09:32
Status:active» fixed

This is fixed now with the "as link" option.

With linking to the image, I'd suggest thickbox or similar - which is supported by views/imagefield/imagecache.

#11

Anonymous - September 20, 2007 - 09:41
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.