我想获取字段的图像路径。我在一个节点,我需要图像的Url为了把它作为内联CSS的背景图像。 我无法找到解决方案。你可以帮我吗?Drupal 7获取图像字段路径
回答
从它的URI得到的图像的人的路:上file_create_url(
file_create_url($node->field_image['und'][0]['uri']);
更多信息)可以在这里找到:http://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7
要获取使用URI的图像样式创建的图像的路径,请使用:
在image_style_url更多的信息()可以在这里找到:http://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7
我有时也使用这样的:
$node = node_load($nid);
$img_url = $node->field_userimage['und'][0]['uri'];
<img src="<?php print image_style_url($style, $img_url) ?>" />
您还可以使用[theme_image_style()](http://api.drupal.org/api/drupal/modules--image--image.module/function/theme_image_style/7)而不是hard-使用主题函数编码''标签 – Laxman13
会更受欢迎:'theme('image_style',array('style_name'=>'name','path'=> $ node-> field_userimage ['und'] [ 0] ['uri'],'alt'=>'Alt text'));' – Clive
看起来不错。我应该开始使用这些功能。 – Kristoffer
恐怕,没有上面的解决方案是正确的。他们不遵循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']);
更多细节在这里: http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
上述代码是完美的。一般来说,大多数人不需要像上面描述的那样做,但是如果你想编写符合Drupal标准的代码,并且在事情发生变化或者其他情况时不会中断,那么就不能强调这是多么重要。 引用代码中的项目,比如$ object ['und'] [0] ['element']是非常糟糕的做法。始终使用field_get_items或等价物。 –
您也可以使用Image URL Formatter模块。它允许改变,以便在字段格式,仅保留网址:
奖励:它有风景的作品,以及:
获得的影像风格网址:
$field = field_get_items('node', $node, 'field_image');
$image_url = image_style_url('landingpage_slider', $field[0]['uri']);
- 1. Xamarin.Forms获取图像路径
- 2. 获取图像的路径
- 3. 从路径获取图像
- 4. 将图像路径src更改为Drupal 7上的data-src
- 5. 从图库中获取图像路径
- 6. 如何从图像的缩略图路径获取图像路径?
- 7. PHP获取图像的文件路径?
- 8. 在KitKat上获取图像路径
- 9. 获取图像文件路径
- 10. 获取CGImageSourceRef的图像路径
- 11. Android从Thumbnail获取图像路径?
- 12. 从css获取图像路径
- 13. 从认证的路径获取图像
- 14. 获取当前图像的路径 - jQuery
- 15. 在WinForm中获取图像路径
- 16. 获取的图像C#路径
- 17. MonoDroid获取完整图像路径,OnActivityResult
- 18. 从图像获取路径几何
- 19. 如何获取图像绝对路径?
- 20. 在plist中获取图像路径
- 21. 获取cocos2d精灵图像路径
- 22. bookmarklet获取图像的完整路径
- 23. jquery选择器获取图像路径
- 24. 获取非servlet中的图像路径
- 25. PHP获取路径和所有子路径(Drupal)
- 26. Drupal 7:限制访问路径
- 27. 在drupal中设置路径7
- 28. 图像不拾取路径
- 29. 图像字段标题<a>在Drupal 7中的标签
- 30. Drupal 7的图像字段大小和上传作物
救了我的命。谢谢! –
这不考虑多语言字段。请参阅下面的@Gergely的答案。即使你认为你的网站“永远”不需要支持翻译,请不要这样做。欲了解更多信息,请参阅http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way –
奇妙..它帮助 –