By neokrish on
Hi,
I want to set custom block in my module to show only on specific node type. The only solution I know to get the node->type into hook_block is as below:
$nid = arg(1);
$node = node_load($nid);
$type = $node->type;
Is it ok to use the above code in hook_block? or is there a better solution to get a node->type inside the block hook?
I am bit worried about loading the node using node_load as it might be memory intensive.
Thanks for your time.
neokrish.
Comments
You shouldn't worry using
You shouldn't worry using node_load(). If you're on a node page, the node object will be statically cached, so nothing extra happens there. You can find more snippets on http://drupal.org/node/64135 - note you can either use arg(1) or menu_get_object().
Hello. I would like to check
Hello.
I would like to check the "node_type" of a list of nodes.
So, using node_load isn't the best solution for me because it will load into the memory all nodes.
can anybody help to get the "node type" by "nid"?
Thanks!
The simplest thing to do is
The simplest thing to do is run a query:
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
get_defined_vars() might do the trick
Check out get_defined_vars() Here's a good write-up: http://www.dottedidesign.com/node/36