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 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R