开发者

Drupal: grab argument from node instead of url for block view?

I have some terms set for a node and a block that I want to grab the arguments from the page but the page is like so:

http://site.com/node/22

but the terms are on the page like so:

term1

how can I get the block to grab the term1 arg and show 开发者_如何学编程the other nodes that has term1?


You cannot just grab data from the page with PHP (without some sort of complicated HTML tree parsing). Instead, I would suggest getting the term data from the node itself. Consider the following:

$node = node_load(arg(1));
// If you're on Drupal 6:
$terms = taxonomy_node_get_terms($node);
// If Drupal 7, your terms should be stored as a term reference field on the node.
$terms = field_get_items('node', $node, 'YOUR TERM REFERENCE FIELD');

foreach ($terms as $term) {
  // Do stuff here.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜