Vishnu Jayan
Vishnu Jayan

Reputation: 159

How to show the image of custom content type in drupal page.tpl.php?

I just created a custom content type in drupal7 and I want to manage the image of that content in my template. <?php print $content; ?> displays all the field of that content. But I just want to show the image only.How can I do so?

Upvotes: 0

Views: 450

Answers (1)

MilanG
MilanG

Reputation: 7114

You must somehow get node id of node that contains that picture (hard-code it or something). Then use node_load() function to load whole node - image field will be one of available fields in loaded node object. Use print_r or something to check out available fields, so you can construct exact code, but it should be something like this:

$node = node_load($nid);
$picture_uri = $node->field_myimagefield['und'][0]['uri'];

// To get image path in specific image style you created:
$picture_style_path = image_style_url('style_name', picture_uri); 

// To get original image path
$picture_original_path = file_create_url($picture_uri);

Then you can directly print picture path into img html tag...

But, are you sure that you are using right template file? If you want template just for your content type you should use node, not page template (which is wrapper for node template).

Upvotes: 1

Related Questions