0

What I am working with it this. I have a custom content type with an image field (field_img) that accepts multiple images so they are stored in an array. what I need to figure out how to do is one of two things and I need to do them from the node--custom.tpl.php if possible.

1: get the size of the $node->field_img array so I can then loop through and assign appropriate HTML id's for each image in the content type.

OR

2: directly loop through the field_img array using maybe foreach() to set the id of each image in the content type to an appropriately unique value.

what I am able to do here works for one value because I can put in the actual index of the instance I am working with but the arrays are not all the same length some have 10 images some have only 6 so I need something that will loop through the array.

Here is the static code that works for one element

<div id="gallery-img-wrapper">  

<?php $i = 0 ?>

<img class="album-image<?php print $i ?>" src="<?php print render (file_create_url($node->field_img['und'][$i]['uri'])); ?>">

</div>

this is inside node--gallery.tpl.php and it works fine but it only displays 1 image and I need 14 or how ever many there are for the instance of the content type.

  • You mention foreach(), but did you try it? Seems to me that it should work. foreach($node->field_img[LANGUAGE_NONE] as $key => $value) – 2pha Feb 22 '13 at 14:05
  • I did try it but I couldn't figure out the syntax. I'll try your snippet thanks. – HKDas Feb 22 '13 at 16:05
  • Ok awesome it did work. I ended up changing the [LANGUAGE_NONE] to ['und'] but it did work either way. Thanks 2pha. you should put in your answer so I can give you a rep point. – HKDas Feb 22 '13 at 16:24
1

You mention foreach(), but did you try it? Seems to me that it should work. foreach($node->field_img[LANGUAGE_NONE] as $key => $value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.