Drupal 7, print only field of type "image" on node.tpl.php

Public

Print only field of type "image" on node.tpl.php.

Get raw version
php
  1. // Fields must be hidden before to achieve this.
  2.  
  3. $bundle_type = $type; // Gives $bundle_type = 'article'; etc
  4. $fields_info = field_info_instances('node', $type);
  5. foreach ($fields_info as $field_name => $value) {
  6. $field_info = field_info_field($field_name);
  7. $field_type = $field_info['type'];
  8. $field_name = $field_info['field_name'];
  9.  
  10. // Notice that $field_info contains
  11. // general data of the field as they appear in the database
  12.  
  13. if ($field_type == "image") {
  14. print render($content[$field_name]);
  15. }
  16. }