By Laurenzio on
There is a way to get $node->nid, inside a block ?
I wanna know whats the current node Id, but global $node doesnt seems to have this variable in blocks.
There is a way to get $node->nid, inside a block ?
I wanna know whats the current node Id, but global $node doesnt seems to have this variable in blocks.
Comments
have you tried arg() function?
the arg() function (http://api.drupal.org/api/function/arg/5)pulls components from a drupal url. perhaps this will return the current node->id?
if the url that being accessed is http://www.example.com/node/4, try the following php in your block:
Mark Sanders
Q Collective
Mark Sanders
Q Collective
thanks
I think this is working only for somethink like: node/55
the problem is that arg(1) is not always my node id, since the url is not always the same.
you may need to add some logic
if the position of the nid changes in the url, here is how to find the $index value for the arg() function:
/this/is/the/nid >> 'this' = arg(0), 'is' = arg(1), 'the' = arg(2), 'nid' = arg(3), and so on...
also, you may want to add the following logic to make sure the url has a numeric nid:
if this doesn't work, could you provide an example of the paths you are using to access your nodes? that way i can be a lot more specific.
Mark Sanders
Q Collective
Mark Sanders
Q Collective
great ! thanks
great ! thanks
this breaks when using path
this works even when using path aliases!
A more current approach would
A more current approach would be