dqp21271 2012-05-02 17:56
浏览 55
已采纳

Drupal - 通过URL获取节点的正文文本?

I'm trying to create a function to retrieve and display just the Body field of a Drupal node, based on a given URL.

Currently, I've extended the functionality of the standard Drupal RSS to do a detection method. This will happen if you enter the following url: http://mysite.com/rss.xml/page=54

That last part is critical - it tells what node ID to load from. As far as code goes, I've modified the node_feed() function in /modules/node/node.module to do the following:

if (stristr($nids, 'page=') !== FALSE) {
 $nid = substr($nids, stripos($nids, 'page=') + 5);
 $result = NULL;

 if ((string)(int)$nid === $nid) {
  $result = db_result(db_query("SELECT `nid` FROM {node} WHERE `nid` = %s AND `type` =  'flashnode'", $nid));
 }

 if ($result) {
   $item = node_load($result);
   print($item->body);
 }
 exit;
}

While this works, we're worried about it for two reasons:

1) Do the results cache? This is a very heavy-load page that will be called a lot.

2) Is there an "official" way to do this? One that uses modules with caching, instead of a semi-hacky workaround?

Thanks in advance for any guidance. -Tom

  • 写回答

1条回答 默认 最新

  • douxiu6835 2012-05-02 20:41
    关注

    You should definitely not be hacking apart the RSS feed in order to create a URL that returns a node's body. You should create a very simple custom module: http://drupal.org/developing/modules

    The Drupal module system is lets you set up a url so that something like /fetch_body/1234 calls the fetch_body() function with $nid=1234 as the parameter. As for caching, you have a lot of options in your custom module. The most obvious would be to use cache_get() and cache_set() to do simple caching on your own based on the node ID.

    What version of Drupal are you using? I would highly recommend the book Pro Drupal Development, just make sure to get the edition that matches your drupal version.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?