cck / contemplate image field and node reference to make an image that links to another node or veiw page
pbz1912 - January 14, 2009 - 19:06
Here goes,
What I want is to have images that link to a different pages:
eg. <a href="node reference path"><img src alt="from image field"></a>
Using cck and contemplate there is no way to get only the path of the node reference. All I can see is <a href="node ref path">Node Title</a> in contemplate's outputs.
Is there any way to get only the node reference path so that I can get the html I want in contemplate or is there another module that does this? I'm using Drupal 6.
Any suggestions would be great.
Thanks in advance,
pbz1912

Ugly, but it will work
If someone knows of a better way to do this, please speak up. Here's what I did.
I created an inline function in my content template which takes the link reference and the image file path reference as arguments. Then, I just parsed out the opening <a> tag, added the image tag with the file path (I did it this way instead of using the full image reference so I could make sure the border="0" attribute was in place), added the closing tags and printed it all.
<?php
function printImgLink($nodeRef, $imgPath) {
$idx = strpos($nodeRef, '>');
$link = substr($nodeRef, 0, $idx + 1);
$link .= '<img src="' . $imgPath . '" border="0" /></a>';
print $link;
}
?>
Here's an example of calling the function with my own specific node references:
<?php
printImgLink($node->field_left_promo_page_ref[0]['view'], $node->field_left_promo_image[0]['filepath']);
?>
It got the job done.