简体   繁体   English

如何使用PHP从单个Drupal节点获取多个图像

[英]How to get multiple images from a single Drupal node using PHP

I have a custom content type in Drupal that allows multiple image uploads through a single field. 我在Drupal中有一个自定义内容类型,它允许通过单个字段上传多个图像。 I want to programmatically access the image URI's, apply my theme, and then get the output one by one. 我想以编程方式访问图像URI,应用主题,然后逐个获取输出。 I can do this with a single image like so, 我可以像这样用一张图片来做

<?php
$image_style_name = 'my_theme';
$image_uri  = $entity->field_image['und'][0]['uri'];
$image = theme('image_style', array('style_name' => $image_style_name, 'path' => $image_uri));

$image = image_style_url($image_style_name, $image_uri); ?>

but I am unsure how to access the entire array of images. 但我不确定如何访问整个图像数组。

For anyone who needs it... the full solution: 对于任何需要它的人...完整的解决方案:

<?php
$image_style_name = 'my_theme';

foreach($entity->field_image['und'] as $key => $value){
$image_uri  = $entity->field_image['und'][$key]['uri'];
$image = theme('image_style', array('style_name' => $image_style_name, 'path' => $image_uri));
$output = image_style_url($image_style_name, $image_uri);    
echo $output;
}
?>

They should be in the $entity->field_image['und'] array so you should be able to loop over the array and theme each one with something like 它们应该在$entity->field_image['und']数组中,因此您应该能够像这样循环遍历数组和主题

foreach($entity->field_image['und'] as $image_field){
  ..etc
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM