JuliaKM Julia Kulla-Mader's Home on the Interweb

Using Imagecache and CCK Imagefield to Add an Image in Drupal

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."

create cck image field 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.

drupal preset namespace 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."

display cck image 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."

set display of cck image 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."

  1. 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->fieldrelatedimages[0]['view']; ?>

<?php print $node->fieldrelatedimages[0]['title']; ?> `