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?

2 Answers 2

$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);
  • 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, 2014 at 2:49
  • Sorry, It seems I dont have enough reputation to up-vote your answer.
    – anthony
    Mar 26, 2014 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, 2014 at 3:24

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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