开发者

drupal node_load and teaser problem

开发者 https://www.devze.com 2023-03-11 18:08 出处:网络
$MrNode = node_load(array(\"nid\" => 679)); $teaser_content = truncate_utf8(strip_tags($MrNode->teaser),400,true,true);
$MrNode = node_load(array("nid" => 679)); 
$teaser_content = truncate_utf8(strip_tags($MrNode->teaser),400,true,true); 

print $teaser_content;

above is the php code I've used to load a drupal node and display certain number of characters our of it... but 开发者_如何学运维it doesn't seem to work... Can someone please help me with this? Thanks a lot!


Are you working with Drupal 6 or 7? Your code worked fine for me in Garland's template.php in Drupal 6. It won't work in Drupal 7, as $node->teaser doesn't exist anymore (see http://drupal.org/node/889058).

This worked for me in Drupal 7:

$MrNode = node_load(1);
$teaser_content = truncate_utf8(strip_tags($MrNode->body['und']['0']['summary']),400,true,true); 
print $teaser_content;

If you're using D7, you will probably also want to change your node_load argument so it takes the node id as an integer, instead of an array, as the default value seems to have changed in D7 (see http://api.drupal.org/api/drupal/modules--node--node.module/function/node_load/7).

You will also need to have a summary, which you can check by calling print_r($MrNode).

Of course, this is only useful if you are using D7 - if you can indicate what version you're using, that'll help in finding the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消