Print node teaser from the bottom

How can I print a teaser from a specific number? It drives 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 way out is the Array.

I also tried this:

 $node = node_load(20); $teaser_content = $node->body['und']['0']['summary']; print $teaser_content; 

But this gives me a summary node, not the teaser specified with <!--break--> .

+4
source share
3 answers

In Drupal 7, there is no $teaser argument to the node_view() function, instead there is a $view_mode argument that accepts a string (usually teaser or full , default is full ). The code you are currently using works fine for Drupal 6.

This code will work for Drupal 7:

 $view_mode = 'teaser'; $nid = 20; $node = node_load($nid); print render(node_view($node, $view_mode)); 
+8
source

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() , since it will be whitescreen if node_load() failed to load node successfully.

+1
source

In Drupal 6, it's easy

 $node = node_load(20); print node_view($node, 'teaser'); 
0
source

Source: https://habr.com/ru/post/1397388/


All Articles