Custom arrangement for fields with multiple values in Drupal 7 In Drupal 6 I used to make every sort of customised markup for CCK fields with multiple values. Usually this happened when I wanted to lay out thumnails for a gallery inside a table: I used to go into the relevant tpl.php file, grab the relevant $field_fieldname variable, loop through it, and print out the 'view' key for it, which contained the styled thumbnail, often linked to the original image and whatever.

Now, I'm a bit confused on how this should be done in Drupal 7. For now, I set up a suboptimal solution that goes like

&lt;section class="gallery"&gt;
    &lt;div class="row first"&gt;
    &lt;?php foreach($content['field_gallery'] as $k =&gt; $v) : ?&gt;
        &lt;?php if(is_numeric($k)) : ?&gt;
            &lt;?php echo render($v) ?&gt;
            &lt;?php if((($k+1) % 4) == 0) : ?&gt;
    &lt;/div&gt;&lt;div class="row"&gt;
            &lt;?php endif ?&gt;
        &lt;?php endif ?&gt;
    &lt;?php endforeach ?&gt;
    &lt;/div&gt;
&lt;/section&gt;


but it's obviously wrong. I can't seem to get my head around this, even after having read lots of docs about the Field API and theming for D7. Ideas?
You've got an explanation on how field_view_field and rendering api for fields work in this blog.

Here you've got an example (extracted from the link above):

$node = node_load($nid);
$field = field_get_items('node', $node, 'field_name');
$output = field_view_value('node', $node, 'field_name', $field[$delta]);


You just need to loop over the $delta value for the fields to render them in a multiple valued field.