How can I print a teaser from a specific nid? It's driving me crazy.
I tried this:
$teaser = TRUE;
$page = FALSE;
$nid = 20;
print node_view(node_load(array('nid' => $nid)), $teaser, $page, FALSE);
but the only output is 'Array'.
I also tried this:
$node = node_load(20);
$teaser_content = $node->body['und']['0']['summary'];
print $teaser_content;
But this is only giving me the summary of the node, not the teaser specified with <!--break-->
.
In Drupal 7 there is no $teaser
argument to the node_view()
function, instead there is a $view_mode
argument which takes a string (usually teaser
or full
, the default is full
). The code you're currently using would work perfectly for Drupal 6 though.
This code will work for Drupal 7:
$view_mode = 'teaser';
$nid = 20;
$node = node_load($nid);
print render(node_view($node, $view_mode));
Use the render()
function.
$teaser = TRUE;
$page = FALSE;
$nid = 20;
print render(node_view(node_load(array('nid' => $nid)), $teaser, $page, FALSE));
Be careful using node_view()
directly on node_load()
as it'll whitescreen if node_load()
fails to successfully load the node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With