http://demo.com/drupal710/sites/default/files/news/4852401.jpg
上传到drupal7 的媒体或文件通常是这样一个地址。
http://demo.com/drupal710 我们可以通过 global $base_url 来获得。
sites/default/files 这一段,在drupal6 里可以通过 file_directory_path() 来获得的,可是在drupal7里被取消了,但是可以在 template.php 里重构这个函数,如下:
function file_directory_path($scheme = 'public') { return file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath(); }
下面的代码就是在 node 页面下获取自定义图片字段里上传的一个或过个图片。 可以建立一个block,运行此段代码。这样你可以任意定于这个block 的位置了,相比内置的位置选择,要灵活的多。
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1); if($nodeid){ $obj = node_load($nodeid); $items = field_get_items('node', $obj, 'field_image'); //echo count($items); if($items){ global $base_url; $a=0; while($a<count($items)) { echo $base_url."/".file_directory_path()."/".file_uri_target($items[$a]['uri'])."\n"; $a++; } } }

Posted on 20,十二 |
Posted by 姚 迎迎 












There are no comments yet