"$nid" for individual pages not working &lt;?php 
  $nid = arg(1);
  $arg0 = arg(0);
  if(isset($nid) &amp;&amp; is_numeric($nid) &amp;&amp; isset($arg0) &amp;&amp; $arg0 == 'node') {
    $node = node_load($nid);
  }
  $theme_img = file_create_url($node-&gt;field_page_cover_image[$node-&gt;language][0]['uri']); //origional image path
  if(isset($theme_img)) {
    // print styled image
    print theme('image_style', array('path' =&gt; $node-&gt;field_page_cover_image[$node-&gt;language][0]['uri'], 'style_name' =&gt; 'page_theme')); 
  }  
?&gt;


I am using the above code to load styled image (from node 6) in page.tpl file. This is working fine in all the pages but when I am trying to load images from individual images by using '$nid' it is not working. 
I don't understand what I made mistake in code due to which I couldn't get the value of '$nid'. Please help.
As you are looking to edit/override node template, it is suggested to place your changes into node.tpl.php where you will get $nid as out of the box. page.tpl.php will not give you node variables by default.

If you still you want to get your code on page.tpl.php you can get $nid from url like arg(1).

Let me know if I miss anything!