Hello!

I am trying to do something simple, but could not find information on the forums.

I am using CCK+imagfield+imagecache to display images in nodes. Everything works fine. I added an imagefield to the book content type and the image is being shown. As I read in the forums I added this code to style.css

.field-type-image img {
float: right;
margin-left: 1em;
margin-bottom: 1em;
border: 3px solid white;
}

to make the image aligned to the right with the text from "body" flowing around it. One thing I need more is to have a line with a smaller font size just below the image containing its description. I made a new CCK Text field (called image_description) but I don't know how to position it at the right place. Should I add something to style.css?

Here is a picture of what I mean: http://erasmusbg.info/image_description.jpg

I would greatly apreciate your help.

Comments

polly-1’s picture

You don't need a new CCK Text field, you can insert your description as alternate text in CCK imagefield and display it under the image.

Add to style.css:

.field-type-image p {
 clear:both;
 font-size: 0.85em;
}

Override phptemplate_imagefield_image in your template.php:

 function phptemplate_imagefield_image
...
/*    return '<img src="'. check_url($url) .'" alt="'.
        check_plain($alt) .'" title="'. check_plain($title) .'" '. 
        $image_attributes . $attributes .' />';   */
    return '<img src="'. check_url($url) .'" alt="'. check_plain($alt) .'" '. 
      check_plain($title) .'" '. $image_attributes . $attributes .' /><p>' . $alt . '</p>';
lluubboo’s picture

Hello, polly!

Thank you for your fast response. Unfortunately I could not make it work.

This is what I did: I added the code you suggested to style.css. I didn't know how to override things in template.php as I can't write code. Still I found the lines in the imagefield.module file and replaced them with your code. When I reloaded the page it stayed the same though. It didn't seem to make any difference. There was no text below the image.

What am I doing wrong?

scottrigby’s picture

hi polly

I tried to override the function in the zen theme for Drupal 6, but it doesn't seem to take effect - even after clearing the cache. Here's my code -- do you see anything I might be doing wrong?:

/**
 * Override Imagefield output (add alt text as caption)
 */
function dlc1_imagefield_image($file, $alt = '', $title = '', $attributes = null, $getsize = true) {
  $file = (array)$file;
  if (!is_file($file['filepath'])) {
    return '<!-- file not found: '. $file['filepath'] .' -->';
  }
  $image_attributes = array();
  if (!$getsize || (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath']))) {
    $attributes = drupal_attributes($attributes);
    $alt = empty($alt) ? $file['alt'] : $alt;
    $title = empty($title) ? $file['title'] : $title;
    $url = file_create_url($file['filepath']);
    return '<img src="'. check_url($url) .'" alt="'.
        check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' /><p>' . $alt . '</p>';
  }
  return '<!-- could not get imagesize, possibly corrupt or non image. '. $file['filepath'] .' -->';
}

Thanks in advance for any insight into this ;)
Scott

open-keywords’s picture

I happend to have the same issue, and found out that the formatter being used was the one from imagecache, then the theme function should be

 function phptemplate_imagecache ($file, $alt = '', $title = '', $attributes = null, $getsize = true) {
// return whateever you like
}
mattyb’s picture

Watching