I have used this module for several months without a hitch. Many useful instructions for CCK + Imagefield + Imagecache + Lightbox2.

Now, trying to push my site a bit further I'm delving into themeing nodes and content types and am not sure how to get images with the correct call to Lightbox2.

What I'm doing:

in a custom node-photos.tpl.php I do:

<?php if ($field_photoimage[0]['filepath']): ?>
<?php print theme('imagecache', 'small', $field_photoimage[0]['filepath'],$title,'',array('class' => 'small')); ?>
<?php endif; ?>

This gets a the field with the CCK fieldname 'photoimage' and outputs the 'small' size image I have specified in Imagecache. Works great in terms of Imagecache functionality. But it seems to break the Lightbox2 augmentation of the image, I no longer have any Lightbox2 functionality when themeing nodes manually as above.

My question is: what can I add to the above code to output the picture with Lightbox2 functionality, just as if I'd not themed the node?

Many thanks.

Comments

stella’s picture

Status: Active » Fixed

I would use the theme('imagefield_image_imagecache_lightbox2') function.

theme('imagefield_image_imagecache_lightbox2', 'small', $field, $item, $node, $rel);

It's best to look through this function and lightbox2_imagefield_image_imagecache to see what the passed in arguments require.

zhte’s picture

Thanks for such a quick reply,

I'm having a bit of trouble figuring what to put in $item. Here's what I've got and I'm doing.

<pre><?php print_r($node); ?></pre>

Calls all things in the node object, which gives:

stdClass Object
(
    [nid] => 3405
    [vid] => 3446
    [type] => photos
    [status] => 1
    [created] => 1221317940
    [changed] => 1221317729
...
    [field_photoimage] => Array
        (
            [0] => Array
                (
                    [fid] => 194
                    [title] => title.jpg
                    [alt] => alt
                    [nid] => 3405
                    [filename] => filename.jpg
                    [filepath] => files/filename.jpg
                    [filemime] => image/jpeg
                    [filesize] => 117501
                    [view] => filename.jpg
                )
        )

So I used the function you kindly suggested and changed $field to $field_photoimage (I alse tried variants like $field_photoimage[0], $field_photoimage[0]['filepath']), I changed $item to 0, filepath, 'filepath' and a number of other variants and $rel to 'lightbox'.

None of these approaches worked. Given the above Node Object I'd be interested in how I could get a lightbox on the photoimage field - I'm clearly not doing something right.

A very gracious thanks.

stella’s picture

It's designed to be used from views or somewhere you have access to the individual field items.

Try:

// $node is the node object you have, so just use that.
$rel = 'lightbox'; // or lightbox[groupname] for groupings, or lightshow[groupname] for a slideshow.

$item = array();
$item['lightbox_preset'] = 'original'; // or if you want to use a imagecache preset, specify that here instead.
$item['nid'] = $node->nid;  // Only do this if you want a link to the node in the caption.
$item['title'] = $item['alt'] = $title;  // Specify the image title or caption here.
$item['filepath'] = $field_photoimage[0]['filepath'];  // Path to thumbnail image.

theme('imagefield_image_imagecache_lightbox2', 'small', $field_photoimage, $item, $node, $rel);
zhte’s picture

That works beautifully, thank you so much.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

dagomar’s picture

It's designed to be used from views

Be that as it may, but where do I find the $node object from a view?

stella’s picture

You'd have to ask someone more familiar with theming views I'm afraid.