imagecache+imagefield+thickbox搭配使用

我按照这个帖子的步骤http://www.drupalchina.org/node/2618,但出来的缩略图是没有链接的,后来到官方翻了些文章,发现需要用到imagecache的最新dev版本。下面把我的安装步骤说一下,参考了这两篇文章:http://drupal.org/node/144139,http://www.drupalchina.org/node/2618。

cck栏位图片链接演示thickbox展示图片演示

下面介绍一下具体步骤。

相关模块:cck、imagefield、imagecache、views、thickbox;后两个不是必需,imagefield需要服务器支持简洁链接,最好是apache服务器。站点存放档案的文件夹(files)必须全局可写。

模块修改:必须先修改imagefield.module,在522行插入如下代码:

<?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']);
}
?>

开始安装:

1、安装模块后,进入imagecache选单,新建一个图片模式,名字随意,将做为存放图片的目录名,如下图:

2、在Add a new action选项下选择scaleupdate preset提交,如图:

3、现在就可以填入图片参数了,宽度和高度,如果你想把这个做为缩略图就填小一点,scale to fit选择:inside dimensions,权重可选可不选。然后update preset提交。点击查看图片

4、按照上述步骤再建立一个大图,或者中图,你想什么图都可以。不建也行。

5、现在任意选择一个内容类型,利用添加一个图片字段,和平常一样设置。

6、字段显示管理,看摘要和全文的选框里,是不是多了一个 XXXXX as link选项?如果你建立了多种图片模式类型,这儿也会有相应的XXXX as link。如图:

7、views也会出现相应的XXXXX as link选项。

8、安装了thickbox模块的话,就会出现Thickbox:XXXXXX的选项。点击查看图片

大功告成,然后就可以到views里随便调用了。

记录个位置。

记录个位置。

--------------------------------------------------------
MaxHtml
QQ群:6703001(人满) QQ群2:5816016 {加入请注明drupal}
--------------------------------------------------------

好,这个比我写的那

好,这个比我写的那个详细的多,嘿嘿

偶也几个位置 ----------

顶一下 顺便建议楼主

顶一下
顺便建议楼主在Firefox下看看:
http://www.500959.com/og/2

这一个页面