Hi,

I am trying to theme a CCK node with image_field which displays a picture from imagecache preset and links to another imagecache preset which is the same picture but bigger with the preset name image_view. I want to use lightbox2 to view the image_view picture.

<a href="link/path to imagecache image_view picture" rel="lightbox">
<?php print theme('imagecache', 'image_thumb', $field_photo[0]['filepath']); ?>
</a>

What is the best way to get the link/path to the image_view preset?

Comments

tommo’s picture

This isn't very pretty but it works for me:

//prepare the image filename for the larger image to display in lightbox
$imgstr = theme('imagecache', 'image_view', $field_photo[0]['filepath']);
$strPos1 = strpos($imgstr, 'http://');
$strPos2 = strpos($imgstr, '"', $strPos1);
$fileName = str_replace(' ', '%20', substr($imgstr, $strPos1, $strPos2-$strPos1));

//no just do the do the output
print('<a href="'.$fileName.'" rel="lightbox[rsimageset]">');
print(theme('imagecache', 'image_thumb', $field_photo[0]['filepath'], $imgNow['alt'], $imgNow['title']));
print('</a>');

There i even put your variables into it.

What would be really nice is a way of directly calling an imagecache theme such as:
theme('imagecache_path', 'image_view', $field_photo[0]['filepath']);
and instead of being given the Only local images are allowed. html to just have the $url returned... anyone got any ideas on how to do this?

andrew_mallis’s picture

A slight variation on your solution, which breaks out the href for the right larger image and uses an imagecache function to create the url.
I came to this solution to assure flexibility if the default files directory changes. Using the preset names instead of hardcoding links assures things don't break. Or, in my case, unbreaks what I broke when I changed my files directory.

$thumbs_class['attributes']['class'] = 'gallery-thumbs';
foreach((array)$node->field_photo_gallery as $item) {
  $lightbox_path = imagecache_create_url('lightbox', $item['filepath'] );
  $caption = check_plain($item['title']).' <br /> '. check_plain($node->title) .' PHOTO GALLERY. <br /> Use right and left arrows or the mouse to navigate';
  $title = check_plain($item['title']);
  print '<a class="gallery-thumbs" title="'.$caption.'" rel="lightbox[photo_gallery]" alt=" " href="'.$lightbox_path.'">'. theme('imagecache', 'square_thumb', $item['filepath'], $alt = 'gallery item', $title, $thumbs_class['attributes']) .'</a>';
}

Andrew Mallis
http://andrewmallis.com

Andrew Mallis
CEO & co-founder @ Kalamuna