Skip to main content
Bounty Ended with 50 reputation awarded by Bala
added 148 characters in body
Source Link
Jimajamma
  • 17.1k
  • 1
  • 28
  • 35

Also, I've left out any logic based upon toggling this on another field's value, but all the information is available in that template to do so.

Also, I've left out any logic based upon toggling this on another field's value, but all the information is available in that template to do so.

Source Link
Jimajamma
  • 17.1k
  • 1
  • 28
  • 35

If you are asking "How can I theme the first image in a multi-value field differently from the remaining images in that field?" you can use a custom field template.

First, copy content-field.tpl.php from the CCK module (found in modules/cck/theme/content-field.tpl.php) to your theme's directory.

Then copy it to content-field-field_NAME_OF_FIELD.tpl.php eg something along the lines of content-field-field_pictures.tpl.php.

NOTE: You must have both content-field.tpl.php and content-field-field_whatever.tpl.php in the same directory in your theme or it won't work.

Inside, it looks basically like this:

<?php if (!$field_empty) : ?>
<div class="field field-type-<?php print $field_type_css ?> field-<?php print $field_name_css ?>">
  <?php if ($label_display == 'above') : ?>
    <div class="field-label"><?php print t($label) ?>:&nbsp;</div>
  <?php endif;?>
  <div class="field-items">
    <?php $count = 1;
    foreach ($items as $delta => $item) :
      if (!$item['empty']) : ?>
        <div class="field-item <?php print ($count % 2 ? 'odd' : 'even') ?>">
          <?php if ($label_display == 'inline') { ?>
            <div class="field-label-inline<?php print($delta ? '' : '-first')?>">
              <?php print t($label) ?>:&nbsp;</div>
          <?php } ?>
          <?php print $item['view'] ?>
        </div>
      <?php $count++;
      endif;
    endforeach;?>
  </div>
</div>
<?php endif; ?>

and you will be wanting to change the <?php print $item['view'] ?> line in the middle.

Dull ax approach, this would do it:

<?php if (!$field_empty) : ?>
<div class="field field-type-<?php print $field_type_css ?> field-<?php print $field_name_css ?>">
  <?php if ($label_display == 'above') : ?>
    <div class="field-label"><?php print t($label) ?>:&nbsp;</div>
  <?php endif;?>
  <div class="field-items">
    <?php $count = 1;
    foreach ($items as $delta => $item) :
      if (!$item['empty']) : ?>
        <div class="field-item <?php print ($count % 2 ? 'odd' : 'even') ?>">
          <?php if ($label_display == 'inline') { ?>
            <div class="field-label-inline<?php print($delta ? '' : '-first')?>">
              <?php print t($label) ?>:&nbsp;</div>
          <?php } ?>
          <?php
            if ($count==1) {
              $first=str_replace('100x100','228x228', $item['view']);
              print $first;
            } else {
              print $item['view'];
            }
          ?>
        </div>
      <?php $count++;
      endif;
    endforeach;?>
  </div>
</div>
<?php endif; ?>

where, if in your CCK configuration you have 100x100 as the imagecache style for this field as the default, it is changed to 228x228 for the first image.

Obviously, if 100x100 appears anywhere else this fails so I am sure something more eloquent could be created. But in either case, clear caches/theme registry and you should be on your way.