Teaser’s thumbnail and main image at full node are the default features using the ‘image module‘ function of Drupal.

Here’s a quick way if you’re in a hurry and don’t want to install other modules such as CCK, Imagecache, Imagefield, Imageapi, etc.. and creating fields at ‘Content Type’, creates presets at Imagecache and so on…

As of this writing, I’m using image module version 6.x-1.0-alpha4. To add caption, open the file ‘image_attach.module (modules\image\contri\image_attach/image_attach.module),’
and add this one line of code

$output .= '
<div class="caption">' . $image->title . '</div>
';

in the *theme the body* function.

/**
 * Theme the body
 */
function theme_image_attach_body($node) {
  $img_size = variable_get('image_attach_size_body_'. $node->type, IMAGE_THUMBNAIL);

  if ($img_size != IMAGE_ATTACH_HIDDEN) {
    drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css');

    $image = node_load($node->iid);
    if (!node_access('view', $image)) {
      // If the image is restricted, don't show it as an attachment.
      return NULL;
    }
    $published = $image->status ? '' : ' image-unpublished';
    $info = image_get_info(file_create_path($image->images[$img_size]));
    $output = '
<div style="width: '. $info&#91;'width'&#93; .'px" class="image-attach-body'. $published .'">';
    $output .= l(image_display($image, $img_size), "node/$node->iid", array('html' => TRUE));
    $output .= '
<div class="caption">' . $image->title . '</div>
';
    $output .= '</div>
'."\n";

    return $output;
  }
}

You can style your caption using CSS in your theme or image module’s CSS

.caption {
}

Note: Back-up your files if you’re updating the image module.

Adding caption:
Enable image attachment in the content type whether it is a story or a page, then at ‘create content,’ you can see this at the bottom as a sample.

sample

sample

The problem is, you can’t edit the text once you saved the image. Haha.

Instead, use ‘Image Assist’ module as another way to add caption to your image.

Advertisements