Using Imagecache and CCK Imagefield to Add an Image in Drupal
August 21, 2007
Figuring out how to get Drupal's imagecache module to work with CCK's imagefield can about as fun as a trip to the dentist. Although I found a lot of articles analyzing the benefits of using Image vs. CCK imagefield, I could not find one source with clear instructions on how to implement imagefield with imagecache. So, here's my stab at an explanation of how to get imagecache to work with imagefield.
1. Install and activate CCK, imagefield, and imagecache. Go to Admin > Content types and select the content type that you want to add an image field to. Click on "Add field" to add an image field. Then, give your field a title, select Image and create your field. The name of my field is "related_images."

2. Set your imagecache presets at Site Building > Image cache. My preset is has the namespace "homepage" and is set to resize with a width and height of 100.

3. Go back to the content type that you added a CCK image to by selecting Content Management > Content types. Click on the name of the content type you previously added an image to. In the content type's menu, select "Display fields."

4. Look to the right of the listing for the image field you created. Set the teaser and body to the namespace you set in step 2. My namespace is "homepage."

5. Add a new article of content using the content type that has your new image field. Upload an image as part of the post and make sure that your image displays at the width and height you set in "Display fields."
6. If you want to have your image display in a template such as node.tpl.php, the following code will print the image and image title for a CCK image field called field_related_images:
<?php print $node->field_related_images[0]['view']; ?>
<?php print $node->field_related_images[0]['title']; ?>
本文详细介绍了如何在Drupal网站中安装并配置CCK模块的Image field与Image Cache模块,实现图片缓存及自定义尺寸显示的功能。通过六个步骤,从安装模块到最终在页面上展示调整大小后的图片,提供了清晰的操作指南。
1575

被折叠的 条评论
为什么被折叠?



