7中的结构发生了变化,该字段首先按语言键(“und”默认为“未定义”),然后您可以按照以下示例进行操作:
// Array of Image values
$images = $node->field_images['und'];
//If you don't know the language, the value is stored in:
$node->language
// First image
$image = $images[0];
// If you need informations about the file itself (e.g. image resolution):
image_get_info( $image["filename"] );
// If you want to access the image, use the URI instead of the filename !
$public_filename = file_create_url( $image["uri"] );
// Either output the IMG tag directly,
$html = '<img src="'.$public_filename.'"/>';
// either use the built-in theme function.
$html = theme(
"image",
array(
"path" => $public_filename,
"title" => $image["title"]
)
);
请注意使用uri
代替 来filename
将图像嵌入页面,因为Drupal 7 中的 File API 更加抽象(以便更容易与 CDN 服务集成)。