I have an 'image' nodetype, containing an imagefield.
And I have a 'parent' nodetype, containing a nodereference field ('childptrs') that associates a set of image-type nodes with this parent node.

I have a view that takes the node-id of a parent-type node as argument, and displays the associated images.

It's all working fine, except ...
I would now like to display the imagefield's description beneath the image. After much head-scratching I have a partial solution that displays the imagefield's description, but not image itself.

My partial solution consists of a custom template file, views-view-field.tpl.php file:

<?php
$data = unserialize($row->node_node_data_field_parent_childptrs_node_data_field_image_field_image_data);
?>
<?php if ($data['description']): ?>
  <div class="image-caption"><?php print $data['description']; ?></div>
<?php endif; ?>

What is missing from this custom template is code to display the actual image.
I see how to obtain the image's file id:

$fid = $row->node_node_data_field_parent_childptrs_node_data_field_image_field_image_fid;

Does anyone know how to display the image, once I know its fid?

Comments

kobnim’s picture

Status: Active » Closed (fixed)

I found the answer:

<?php
$data = unserialize($row->node_node_data_field_parent_childptrs_node_data_field_image_field_image_data);
$fid = $row->node_node_data_field_parent_childptrs_node_data_field_image_field_image_fid;
$file = field_file_load($fid);
?>
<?php print  theme('imagecache', $my_imagecache_preset, $file['filepath']); // print the image?>
<?php if ($data['description']): ?>
  <div class="image-caption"><?php print $data['description']; ?></div>
<?php endif; ?>