0

I'm making a custom directory navigation using the PHP code filter, and putting the code in a block. I need to detect when a user navigates to a taxonomy term page, and extract data related to the term so I can display the children of that term, just like a web directory.

1 Answer 1

1

Since there is no global variable that you could use to load the node, you will have to use code like the following:

<?php
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
$node = node_load(arg(1));
}
dsm(get_defined_vars());
?>

The dsm(get_defined_vars()); part is of course optional and will only work if you have the devel module enabled. However, if you do have devel, you will be able to see the whole $node object and the tags associated with the specific node.

Notice, that if you are in a term page, you can use the same principle to load a specific term. For example:

<?php
if ( arg(0) == 'tag' && is_numeric(arg(1)) && ! arg(2) ) {
$term = taxonomy_term_load(arg(1));
}
dsm(get_defined_vars());
?>
2
  • Yes, that gives me something to work with.
    – J-Fiz
    Commented May 16, 2011 at 2:10
  • please note that arg(0) in taxonomy pages is "taxonomy" not "tag", and also the term id its on arg(2), arg(1) its equal to "term" (taxonomy/term/123) Commented Nov 29, 2015 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.