Some basic help?

Hi Guys,

Just wondering whether anyone could offer any advice with an issue I'm having for my University assignment.

I've created a custom image field in Drupal 7 called 'field_featured'

What I've done is made about 12 articles each with an image uploaded in the featured field area as above.

My problem is trying to call the image by php into my custom page. I've looked across the internet and have not found a solution and know it's going to be something mega simple.

I've tried using the following as the latest...

<?php if ($node->field_featured[0]):
         print $node->field_featured[0]["filepath"];
         endif; ?>

This does not display anything and usually throws up an error.

I'm quite a novice with php and this is the first time I've used Drupal so go easy on me and hopefully someone will put me out of my misery. 

Many thanks in advance for any help. 

 

lavjaman's picture

Issues

Firstly 

<code>

 

<?php if ($node->field_featured[0]): ?>

<?php print $node->field_featured[0]["filepath"]; ?>

<?php endif; ?>

 

</code>

Secondly

Use the theme_image function for display an image. 

So your code will look like this in the end:

<code>

 

<?php if ($node->field_featured[0]): ?>

  <?php 

    $variables = array(

      'path' => $node->field_featured[0]["filepath"],

    );

    print theme('image', $variables);

  ?>

<?php endif; ?>

 

</code>

 

sibiraj's picture

code img

 

<code>

<?php

 

 print theme('image', array('path' => (isset($node->field_featured[0]["filepath"])) ? $node->field_featured[0]["filepath"] : 'your_no_image_path'));

?>

</code>