我想获得一个字段的图像路径.我在节点中,我需要图像的Url才能将其作为内联css中的背景图像.我找不到解决方案.你能帮助我吗?
Mun*_*ine 51
从它的URI获取图像的路径:
file_create_url($node->field_image['und'][0]['uri']);
有关file_create_url()的更多信息,请访问:http://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7
要使用其URI的图像样式创建图像的路径,请使用:
image_style_url($style, $node->field_image['und'][0]['uri']);
有关image_style_url()的更多信息,请访问:http://api.drupal.org/api/drupal/modules!image!image.module /function/image_style_url/7
42d*_*Ltd 20
我担心,上述解决方案都不正确.他们不遵循Drupal标准.
// field_video_image is the name of the image field
// using field_get_items() you can get the field values (respecting multilingual setup)
$field_video_image = field_get_items('node', $node, 'field_video_image');
// after you have the values, you can get the image URL (you can use foreach here)
$image_url = file_create_url($field_video_image[0]['uri']);
Run Code Online (Sandbox Code Playgroud)
更多细节:http: //www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
我有时会用这个:
$node = node_load($nid);
$img_url = $node->field_userimage['und'][0]['uri'];
<img src="<?php print image_style_url($style, $img_url) ?>" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
47670 次 |
最近记录: |