How to print an image field on all the basic pages only? In my custom type "Page" I've added an image field (field_page_cover_image) and applied image style to it.

&lt;?php
  $field = field_get_items('node', $node, 'field_page_cover_image');
  if($field){
     $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 have a requirement show this image (if uploaded) in all basic pages only (in a separate div container). For this I added the above code in `page.tpl.php

This code is working fine in all the pages but when I load search or other pages, I am getting error, as they don't have this field ($field).
I suggest you to use template_preprocess_page and save your image to a variable. You can refer the below code.

function mytheme_preprocess_page(&amp;$vars) {
     $node = $vars['node'];
     $field = field_get_items('node', $node, 'field_page_cover_image');
      if($field){
         $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
            $imagevariable = theme('image_style', array('path' =&gt; $node-&gt;field_page_cover_image[$node-&gt;language][0]['uri'], 'style_name' =&gt; 'page_theme'));
           $vars['myImage'] = $imagevariable;
        }
      }  
}


You can use $myImage variable to print the image in the tpl file :)