How to use node_load()?
Hi m a bit confused that how to retrieve node title by using this code
node_load($nid); $title=$nid->title;
i have done this coding in block and i wants to retrieve from node id for displaying开发者_Python百科 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
Here is the reference for node_load
http://api.drupal.org/api/function/node_load
It returns an 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.
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).
Load with a numeric node 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;
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"
NODE LOAD BEST PRACTICES
If you are loading a lot of 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):
$nid = 55; $node = node_load($nid, NULL, TRUE);
精彩评论