How to add classes to image fields set to Unlimited and a "rel" attribute to the  tag that wraps them I have an image field set to Unlimited and I have some questions on how to display them:


How do I display only the first image while all the rest are hidden (has class="hide")?
Add a rel="something" attribute to each &lt;a&gt; which wraps &lt;img&gt;


Answer to #1 found! After several tests, simply capture the field by adding this to your field.tpl.php file. This will insert the hide class to all succeeding images after the first one.

&lt;?php if( $element['#field_name'] == 'field_gallery') : ?&gt;  
  &lt;div class="&lt;?php print $classes; ?&gt;" &lt;?php print $attributes; ?&gt;&gt;
    &lt;div &lt;?php print $content_attributes; ?&gt;&gt;

      &lt;?php $i = 0; foreach ($items as $delta =&gt; $item) : ?&gt;

        &lt;div class="field-item &lt;?php if($i &gt; 0) print 'hide '; print $delta % 2 ? 'odd' : 'even'; ?&gt;"&lt;?php print $item_attributes[$delta]; ?&gt;&gt;
          &lt;?php print render($item); $i++; ?&gt;
        &lt;/div&gt;

      &lt;?php endforeach; ?&gt;

    &lt;/div&gt;
  &lt;/div&gt;
&lt;?php endif; ?&gt;
Don't you want to use a module like Views Slideshow: Dynamic Display Block to produce what you're looking for ?

If not you should create a specific template for your field using a name like field--field-name.tpl.php (Drupal 7 Template Suggestions), put it in you theme folder and customize it.

You can use theme_imagecache() if you're on Drupal 6 or theme_image_style() on Drupal 7.

$img = theme('image_style', 
             array('style_name' =&gt; 'thumbnail', 
                   'path' =&gt; $content['field_image'][0]['#item']['uri']
                  ));


Then you wrap your images in a using l():

$attributes = Array('rel' =&gt; 'rel_text');

echo l('yourpath', $img, array('html' =&gt; TRUE, $attributes));