Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm trying to print the image field from a node using the nid in the url.

$nid = $_GET['field_item_request'];

Is there a specific way to do this?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
$nid = arg(1);
$node = node_load($nid);
$image = field_get_items('node', $node, 'field_item_request');
$output = field_view_value('node', $node, 'field_item_request', $image[0]);
print render($output);
share|improve this answer
    
Thanks for pointing me in the right direction! Since I was trying to get the nid from an argument in the url I had to edit it a bit. This is what worked for me: $nid = $_GET['field_item_request']; $node = node_load($nid); $image = field_get_items('node', $node, 'field_image'); $output = field_view_value('node', $node, 'field_image', $image[0]); print render($output); –  anthony Mar 26 at 2:49
    
Sorry, It seems I dont have enough reputation to up-vote your answer. –  anthony Mar 26 at 2:54
    
Welcome to SO. If one of the answers above fixes your issue, you should accept it (click the check mark next to the appropriate answer). That does two things. It lets everyone know your issue has been resolved, and it gives the person that helps you credit for the assist. –  Anil Sagar Mar 26 at 3:24
add comment

I needed to add a specific style to my image. So I modify the code above to fit my needs. Hopefully it will help somebody out.

  $nid = $_GET['field_item_request'];      
  $node = node_load($nid);
  $image = field_get_items('node', $node, 'field_image');
  $image_output = render(field_view_value('node', $node, 'field_image', $image[0], array('settings' => array('image_style' => 'medium', 'label' => ''))));

  print render($image_output);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.