开发者

Drupal's category (taxonomy) name of article (node)?

Developing my custom Drupal开发者_JS百科's theme. it will contain custom node.tpl.php file.

How can i get and print related taxonomy names of selected node?

Tnx in adv!


EDIT: Doh, my apologies, I'm just now seeing the Drupal 7 tag, specifically. It appears this thread has some possible solutions: http://drupal.org/node/909968

With D6 (not 100% about D7) In the node's template .php files (and similarly, in a view or most anywhere you have access to a node's properties with custom PHP, like a View or Block), you can use the following:

// returns array of taxonomy objects for given node
$tax_terms = taxonomy_node_get_terms($node);

// prints each term name
foreach ($tax_terms as $tax) {
    print $tax->name;
}

Also, there's a few useful Drupal functions for cases like this:

// print_r's all properties of a given node, similar to devel
dpr($node);

// using this in the above 'for' look will give you all properties of each taxonomy object
dpr($tax);

Here's a website that lists a few more of these functions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜