Hi All,

I've been having a problem for a while but I kept finding ways around it. Why is it that when I use the following code it doesn't work -

$currentnode = node_load(array('nid'=>31)); 
print $currentnode->teaser . "<br />";

The teaser, nid and title variables seem to work ok but when I try to print teasers or even attached images or other fields, it doesnt return anything.

Thanks!!!

Comments

sfa’s picture

Anyone? This must be a common problem surely.

alan d.’s picture

Depending on how much info you need:

<?php

  $teaser = TRUE;
  $page = FALSE;
  $nid = 31;
  $node = node_build_content(node_load(array('nid' => $nid)), $teaser, $page);
  $node->teaser = drupal_render($node->content);


?>

Alan Davison
www.caignwebs.com.au

Alan Davison
sfa’s picture

Dude, you are a star, I tried it and it works!!!

Just one last thing, that doesnt recognise the template created in contemplate, is there any way to use that layout?

You saved me SO much time.

alan d.’s picture

You will have all the data in the node, other than the stuff called via nodeapi alter. Throw in this step:

node_invoke_nodeapi($node, 'alter', $teaser, $page);

And see what comes out of:

$output = theme('node', $node, $teaser, $page);

Would be easier just to call node_view in this case, lol

Eg:

print node_view(node_load(array('nid' => $nid)), $teaser, $page, FALSE);


Alan Davison
www.caignwebs.com.au

Alan Davison
sfa’s picture

The node_view() worked, thanks again, saved me days!!!

Sepero’s picture

Great stuff Alan.

node_view() allowed me to print my teasers through the fuzzy search interface instead of the lame default. Thank you