fossie@drupal.org

Joined: 04/05/2008
Juice: 315
fossie@drupal.org wrote:

Regarding to the images:

if you use:

<?php
$imagePath
= $node->field_image_cache['0']['filepath'];?>

<div id="image"><img src="/files/imagecache/product/<?php print $imagePath; ?>" alt="Title"></div>

and there is no image, no image is display at all and there will be the image not found symbol.

While using the foreach (I prefer this way), without checking if their is an image, you'll get an error in 'foreach'. I check if $node->field_image_cache is not NULL.

<?php
if (!$node->field_image_cache == NULL) {
foreach (
$node->field_image_cache as $image) {
// ... // display image
}
}
?>

Is their a better way to display images in custom node-product.tpl.php?

TIA,
Fossie

Fossie, your code is not working for me.

Would anyone help me improve the following code:
This is the way i'm currently showing my Lightbox images but I would like to make a check on the images, before showing them (to prevent the "image not found" on IE).

<!--show default image first, then others-->
<div class="product_image">
<?php $imagePath = $node->field_image_cache['0']['filepath']; ?>
<a href="<?=base_path()?><?=$imagePath?>" rel="lightbox[prod]"><img src="<?=base_path()?>files/imagecache/product/<?=$imagePath?>" alt="<?=$title?>" title="<?=$title?>" class="imagecache imagecache-product"></a>

<ul class="other_imgs">
<?php foreach ($node->field_image_cache as $images) { if ($images['filepath'] != $imagePath) { ?>
   <a href="<?=base_path()?><?=$images['filepath']?>" rel="lightbox[prod]" title="<?=$title?>">
   <img src="<?=base_path()?>files/imagecache/uc_thumbnail/<?=$images['filename']?>" alt="<?=$title?>" class="imagecache imagecache-uc_thumbnail"></a>
    <?php } } ?>
</ul>
</div>
<!--/show default image first, then others-->

This works perfectly btw, except when there are no images attached and you get the "image not found" .

Nifty Products Tutorial Part 1 By: mykz- (132 replies) Wed, 03/19/2008 - 19:04