Get the NID from url
If you are wanting to use the nid of the node reference field inside a node template, you could grab it as $node-&gt;FIELDNAME[0]['nid'] (D6 anyway, add an ['und'] or something similar in the mix for D7 :)  Otherwise, a lot of other examples are given in the article @refineo references above.