<img src="imagefile" class="caption" />
Imagefield で画像をアップロードしていますが、Imagefield によってレンダリングされる画像に対して定義されたクラスがないため、クラスを追加したいと考えています。
これは Drupal 6 で可能ですか?
<img src="imagefile" class="caption" />
Imagefield で画像をアップロードしていますが、Imagefield によってレンダリングされる画像に対して定義されたクラスがないため、クラスを追加したいと考えています。
これは Drupal 6 で可能ですか?
template.phpにコピーして MYTHEME_imagefield_image() に名前を変更することで、 theme_imagefield_image()関数をオーバーライドできます。次のようになります。
function MYTHEME_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
//
// ... same contents as the original one, except:
//
$attributes['class'] = $attributes['class'] ? "{$attributes['class']} my-custom-class" : 'my-custom-class';
$attributes = drupal_attributes($attributes);
return '<img '. $attributes .' />';
}
...あなたのtemplate.phpで。
そしてキャッシュクリア!:>
編集:
Imagecacheモジュールを使用している場合は、代わりにtheme_imagecache()関数を上書きして、次のようにします:
function MYTHEME_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE, $absolute = TRUE) {
// Check is_null() so people can intentionally pass an empty array of
// to override the defaults completely.
if (is_null($attributes)) {
$attributes = array('class' => 'imagecache imagecache-'. $presetname);
}
if ($getsize && ($image = image_get_info(imagecache_create_path($presetname, $path)))) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
}
// These two lines are what you need
$custom_class = 'your-custom-class';
$attributes['class'] = $attributes['class'] ? "{$attributes['class']} {$custom_class}" : $custom_class;
$attributes = drupal_attributes($attributes);
$imagecache_url = imagecache_create_url($presetname, $path, FALSE, $absolute);
return '<img src="'. $imagecache_url .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}
...あなたのtemplate.phpファイルで。
正確に何をしようとしていますか?css を使用して imagefield フィールドの出力のスタイルを設定しようとしている場合は、前の div のクラスを使用できます。したがって、html が次のようになっている場合 (私の場合は、imagefield と imagecache を使用しています):
<div class="field field-type-filefield field-field-images"> <!-- created by imagefield -->
<div class="field-items">
<div class="field-item odd">
<a class="imagecache imagecache-thumbs imagecache-imagelink imagecache-thumbs_imagelink" href="http://yoursite/sites/default/files/originalFile.jpg">
<img alt="" src="http://yoursite/sites/default/files/imagecache/thumbs/originalFile.jpg">
</a>
</div>
</div>
</div>
css ファイルで、次のようなものを使用して画像のスタイルを設定します (この例では、画像を下に配置するのではなく、横に配置して、ある種のギャラリーを作成します)。
.field-field-images img
{
float: left;
margin-right: 8px;
margin-bottom: 8px;
}