Html 如何使用 node_load()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3890722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use node_load()?
提问by pranoti
Hi m a bit confused that how to retrieve node title by using this code
嗨 ma 有点困惑如何使用此代码检索节点标题
node_load($nid); $title=$nid->title;
node_load($nid); $title=$nid->title;
i have done this coding in block and i wants to retrieve from node id for displaying image.that images are normally uploaded at the site by using filezilla and it has same name as the node title.i have tried many forms of node_load(),but i m failure.so please tell me right option for this. Thanks all.-Pranoti
我已经在块中完成了这个编码,我想从节点 id 中检索以显示图像。通常使用 filezilla 在站点上上传图像,并且它与节点标题具有相同的名称。我尝试了多种形式的 node_load(),但我失败了。所以请告诉我正确的选择。谢谢大家。-普拉诺蒂
回答by Sid Kshatriya
Here is the reference for node_load
这里是参考 node_load
http://api.drupal.org/api/function/node_load
http://api.drupal.org/api/function/node_load
It returnsan object which is the node.
它返回一个对象,它是节点。
$node = node_load($nid); // $nid contains the node id
$title = $node->title;
Please get a good book on Drupal Module development to learn the fundamentals.
请找一本关于 Drupal 模块开发的好书来学习基础知识。
回答by David Eads
Your question is a little confusing. Could you clean it up and explain better what you are trying to accomplish? In all events:
你的问题有点混乱。你能把它清理干净并更好地解释你想要完成的事情吗?在所有事件中:
Node load takes either an numeric argument or an array of parameters to query, and returns a single node object. (As already mentioned, here's the API documentation: http://api.drupal.org/api/function/node_load).
节点加载采用数字参数或参数数组进行查询,并返回单个节点对象。(如前所述,这里是 API 文档:http: //api.drupal.org/api/function/node_load)。
Load with a numeric node id:
使用数字节点 ID 加载:
$nid = 55;
$node = node_load($nid);
$title = $node->title;
Load by querying on title:
通过查询标题加载:
$title = 'How to serve man';
$node = node_load(array('title' => $title));
$body = $node->body;
回答by DEVARAJ JOHNSON
you can also load multiple node load efficiently by using the following code
您还可以使用以下代码高效加载多个节点负载
<?php
$type = "product_type";
$nodes = node_load_multiple(array(), array('type' => $type));
foreach($nodes as $products):
?>
<?php print $products->nid; ?>
<?php print $products->title; ?>
<?php endforeach; ?>
also you can query any thing in the node load for example we have used type in query but we can also use title as mentioned in the above post by "David Eads"
您也可以查询节点负载中的任何内容,例如我们在查询中使用了类型,但我们也可以使用“David Eads”在上面的帖子中提到的标题
回答by Satya
If you are loading a lotof nodes with node_load(), make sure to use the $reset parameter so that every node isn't kept in the function's static cache (and increasing memory usage):
如果您使用 node_load()加载大量节点,请确保使用 $reset 参数,以免每个节点都保留在函数的静态缓存中(并增加内存使用量):
$nid = 55; $node = node_load($nid, NULL, TRUE);
$nid = 55; $node = node_load($nid, NULL, TRUE);