By ninetwenty on
How can I get at the node object from a PHP page? I've tried using node_load and arg(1) but that only works if I'm actually viewing the page, not when listed as a teaser.
How can I get at the node object from a PHP page? I've tried using node_load and arg(1) but that only works if I'm actually viewing the page, not when listed as a teaser.
Comments
It depends on what you want to do
The node object ($node) is only defined in page.tpl.php and the trick of looking at arg(0) == 'node' and using arg(1) as the nid only works when viewing a single node on the page. So it would probably help if you explained what you are trying to do and people would be better able to help you.
I need to be able to get the
I need to be able to get the current node id and pull some related data from a table and display this in the body. Looks like I can't do it as there is no way to get the real current node.
Two ways to approach this
You can write a module that implement the nodeapi hook which for your purposes would be called when a node is viewed ($op == 'view') at which point you could add to the body of the node.
Second approach is to handle it in node.tpl.php and add the information when the node is displayed.
So a possible solution would
So a possible solution would be to use a regular expression to replace some marker text in the body with the content I want? For example:
That would be one way
In this case because you want to replace a marker you could also use the filter hook. The filter hook would be useful if you wanted to be able to specify options/parameters for what should be included.
And the filter hook has
And the filter hook has access to the node object? If it does that would be perfect.
Actually the body/teaser
Actually the body/teaser (depending on context), it does not have access to the complete node (or even "know" it is being used to filter a nodes content.