How can I access $terms from page.tpl.php?

kimangroo - May 31, 2007 - 23:27

It seems that page.tpl.php recognises the existence of $node->taxonomy but I can't seem to get the individual terms (complete with links) that are associated with a node when the node is in single view.

Can anyone help?

I honestly don't know the

dan33 - June 1, 2007 - 02:53

I honestly don't know the real answer to your question (never built a web site with Drupal, just checking it out and saw your post), but I was browsing through taxonomy.module (doing a search for "theme") and found this starting on line 16:

/**
* Implementation of hook_link().
*
* This hook is extended with $type = 'taxonomy terms' to allow themes to
* print lists of terms associated with a node. Themes can print taxonomy
* links with:
*
* if (module_exists('taxonomy')) {
*   $terms = taxonomy_link('taxonomy terms', $node);
*   print theme('links', $terms);
* }
*/
function taxonomy_link($type, $node = NULL) {
...

Hope that helps.

Thanks

kimangroo - June 3, 2007 - 01:53

Thanks for the info! I'm pretty new to Drupal as well so don't really know what I'm talking about but I think hook_ stuff has to be implemented in modules as opposed to in templates for themes like page.tpl.php.

I managed to get what I wanted by using something like this:

$terms = taxonomy_node_get_terms($node->nid);
rsort($terms);
$newTerm = '<a href="/taxonomy/term/' . $terms[0]->tid . '">' . $terms[0]->name . '</a>';
print $newTerm

Which I mashed together from a few other posts I found. It's probably the wrong way to do this and won't work if you have more than one term I guess, so if anyone wants to show me the correct way, I'd be very grateful!

Thanks Boss

dinesh kudtarkar - November 18, 2008 - 05:04

Thanks kimangroo

That really helped me

Subscribing.So with this

Summit - November 27, 2008 - 09:01

Subscribing.
So with this Snippet the $terms can be shown on taxonomy pages (page-taxonomy.tlp.php)?
Also for more than one vocabulary?
Greetings,
Martijn

 
 

Drupal is a registered trademark of Dries Buytaert.