简体   繁体   English

来自nid的打印节点预告片

[英]Print node teaser from nid

How can I print a teaser from a specific nid? 如何从特定的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--> . 但这只是给了我节点的摘要 ,而不是<!--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 ). 在Drupal 7中, node_view()函数没有$teaser参数,而是有一个$view_mode参数,它接受一个字符串(通常为teaserfull ,默认为full )。 The code you're currently using would work perfectly for Drupal 6 though. 您目前使用的代码可以完美地用于Drupal 6。

This code will work for Drupal 7: 此代码适用于Drupal 7:

$view_mode = 'teaser';
$nid = 20;

$node = node_load($nid);

print render(node_view($node, $view_mode)); 

Use the render() function. 使用render()函数。

$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. 请小心在node_view()直接使用node_load()因为如果node_load()无法成功加载节点,它将自动进行node_load()

In Drupal 6 it's just 在Drupal 6中它只是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM