By herbivorous on
I'm working in Xtemplate designing a custom block. I want to display "related content", so I need the Node ID# so I know what content is related. My code so far works, except that I can't figure out how to access the nid! $node->nid and for that matter $node are empty, global $node; doesn't seem to help, nor using $GLOBALS["$node"]. It seems like there must be a simple answer that I'm too new to PHP and Drupal to know when I've stumbled across it.
Comments
I beat it!
This may be bad Drupal, bad PHP, and simply bad form, but I added these two lines to index.php
global $mynid;
$mynid = arg(2);
As 14 and 15, I think, with a comment before to indicate that I'd monkeyed. This allows me to pass the node or taxonomy ID on to my custom block, which then uses taxonomy_node_get_terms_by_vocabulary to generate a list of stories from the same author, within the same research project, and/or on the same "hot topic" (the selection of boxes is contingent on which of the vocabularies is present, but that's another story.)
Hmm, I wonder if simply "arg(2)" would have worked . . .
Actually, yes
I was able to pull the NID from arg(2)
$mynid = arg(2);
in my custom block code, allowing me to remove my index.php hack.
Could you share?
Herbivorous, I've been trying to do the same thing. Can you share the code you developed? I'm trying to display blocks when nodes belonging to a particular taxonomy item are called. I'd be much obliged if you could share what you created.
If you're willing, email to norden AATT idaalliance DDOOTT org. Thanks.
- W
Code
It is here