Hi,

I need a url for a node. This is so that I can have one page which says "Business?" and then that link will take the user to the business page. I have created a field in the page content type called OtherPageLink which is a Node Reference.

I then have this in my code:

<a href="<?php print $base_path . '?q=' . $node->field_OtherPageLink[0]['view'];?>" class="quote_other_user">Click Here</a>

Unfortunately, the html being created is wrong as that php is creating an anchor all of its own. I simply want just the url in plain text so I can add it to my own anchor.

Can someone point me in the right direction please? I don't have a clue where to start!

Thanks,
Paul.

Comments

techypaul’s picture

Hi,

This is driving me mad. I want to link around an image, using the node reference but cannot find out how to do it. Any ideas would be much appreciated.

Thanks,
Paul.

peterjlord’s picture

I think the url function will do what you require combined with changing
$node->field_OtherPageLink[0]['view']; to $node->field_OtherPageLink[0]['nid'];

<?php
  $url = url('node/' . $node->field_OtherPageLink[0]['nid']);
?>
techypaul’s picture

Thank you so much for that. I didnt even know about the nid bit.

peterjlord’s picture

krumo is a really useful tool and part of the devel module. Once installed you can then type

<?php
   krumo($node->field_OtherPageLink);
?>

And you get a nicely formated display of all the variables contained in the array so you know what you've got to play with and stops a lot of frustration.