dongyinglan8707 2011-06-06 06:07
浏览 32
已采纳

drupal node_load和预告片问题

$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!

  • 写回答

1条回答 默认 最新

  • doufubu2518 2011-06-06 08:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看