Hit my next problem; hope someone out there can point me in the direction since I'm fairly sure this one is easier than the last.

I've overwritten my CCK created node template (node-content-car.tpl.php) so that I can completely control the format rather than output $content. My first problem is I want to output thumbnails (I'm using upload_image module) with links to the full image node and I can't for the life of me get it to work. I thought the code below would do the trick.

<?php if ($files): ?>
<tr><td class="upload-image-images" colspan="2">
<?php
foreach ($files as $file) { print l(image_display($file, 'thumbnail'),'node/'.$file->nid, array(), null, null, FALSE, TRUE); }
?>
</td></tr>
<?php endif; ?>

Unfortunately that outputs

<tr><td class="upload-image-images" colspan="2">
<a href="/public_html/cnl-drupal/node/38"></a>
<a href="/public_html/cnl-drupal/node/32"></a>
</td></tr>

I guess that's a problem with how I'm using the image_display function, right?

My second question is regarding output of normal fields. At the moment I'm outputting each field individually meaning if I add any more fields I have to go back and add them to the template. How would I grab all fields for the node and cycle through each of them, outputting to the screen?

Many thanks!

Comments

whereisian’s picture

I just opened a support issue about this: http://drupal.org/node/79209

coreyp_1’s picture

image_display() expects $file to be a node object. Here is my attempt:

<?php if ($files): ?>
<tr><td class="upload-image-images" colspan="2">
<?php
foreach ($files as $file) {
  $image = new StdClass();
  $image->nid = $file->nid;
  image_load($image);
  print l(module_invoke('image', 'display', $image, 'thumbnail'), "node/$image->nid", array(), NULL, NULL, FALSE, TRUE);
}
?>
</td></tr>
<?php endif; ?>

NOTE: code not tested.

- Corey

whereisian’s picture

Thanks for the fast reply! Please excuse my extreme noobishness. I'm learning fast.

The following code:

	<?php if ($files): ?>
		<div class="upload-image-images">
		<?php
		foreach ($files as $file) {
		  $image = new StdClass();
		  $image->nid = $file->nid;
		  image_load($image);
		  print l(module_invoke('image', 'display', $image, 'thumbnail'), "node/$image->nid", array(), NULL, NULL, FALSE, TRUE);
		}
		?>
		</div>
	<?php endif; ?>

Renders this:

<div class="upload-image-images">
  <a href="/?q=node/1" class="active"></a><a href="/?q=node/1" class="active"></a>
</div>

What do I need to reference to get only the

to display?
<div class="upload-image-images item-list">
  <ul>
    <li><a href="/?q=node/723"><img src="http://localhost/files/images/Ancestral%20Spirits.thumbnail.JPG" alt="" title="" class="image thumbnail" width="200" height="180"></a></li>

    <li><a href="/?q=node/724"><img src="http://localhost/files/images/III-G-1042.thumbnail.JPG" alt="" title="" class="image thumbnail" width="130" height="200"></a></li>
  </ul>
</div>

The previous support request is now here.

Cheeers,

Ian

iandit’s picture

I had a similar situation. I use flexinode though and needed to rebuild the attachment list with non-image file links and thumbnails for images. After looking at the upload_image module code I decided to copy/paste the whole attachment list generating section below into a custom function in my template.php and call that function from my node specific template file node-flexinode-x.tpl.php

function list_attachments($node)

      if (variable_get("upload_$node->type", 1) == 1 && $node->files && $node->nid && user_access('view uploaded files')) {
        $images = upload_image_load($node);
        // We use CSS to hide the attachement table created by upload.module,
        // we'll re-create the table but only list non-image files.
        theme_add_style(drupal_get_path('module','upload_image') .'/upload_image.css');

        $rows = array();
        $thumbnails = array();

        // Build list of attached files
        foreach ($node->files as $fid => $file) {
          if ($file->list) {
            if (!isset($images[$fid])) {
              $rows[] = array(
                '<a href="'. check_url(file_create_url($file->filepath)) .'">'. check_plain($file->filename) .'</a>',
                format_size($file->filesize)
              );
            }
            else {
              $image = new StdClass();
              $image->nid = $images[$fid]->nid;
              image_load($image);
              $thumbnails[] = l(module_invoke('image', 'display', $image, 'thumbnail'), "node/$image->nid", array(), NULL, NULL, FALSE, TRUE);
            }
          }
        }

        // Add the attachments list
        if (count($rows)) {
          $header = array(t('Attachment'), t('Size'));
          $node->body .= theme('table', $header, $rows, array('id' => 'upload-image-attachments'));
        }
        if (count($thumbnails)) {
          $node->body .= theme('upload_images', $thumbnails);
        }
      }

}

This code is in the node hook under case 'view': on line 61 and below.
If you only need thumbs and not the other files just strip out some code. But this way 100% replicates the module's attachment display.

Hope this helps,

Mike