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,



mk31762’s picture

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.

    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:

    printImgLink($node->field_left_promo_page_ref[0]['view'], $node->field_left_promo_image[0]['filepath']);

It got the job done.

Jon Nunan’s picture

If you have the time, it's pretty easy to write a CCK formatter.

In a rush though you could override one of the formatter's existing theme functions. so in your theme's template.php you'd have:

function MYTHEME_nodereference_formatter_default($element) {
  $output = '';
  if (!empty($element['#item']['nid']) && is_numeric($element['#item']['nid'])) {
	$output = 'node/'.$element['#item']['nid'];
  return $output;

Then just use views 2 new 'rewrite field' ability to put it inside some anchor tags.

Keep in mind that, it'll override that particular formatter everywhere it's used. So you really should just add a new formatter. See for some basic examples.

trefor’s picture

This looks interesting but I don't know where to start with it.

I have a page that is referencing some other pages and I want to pull in thumbnails and content not just the title link.

Can someone suggest a starting point on what to read?