In Drupal 6, I am customizing a view where I am trying to make the taxonomy terms work in all the page template files.

This is the code in the template.php file.

function getTermsName($taxonomy_id) {
  $terms = taxonomy_get_term($taxonomy_id);
  return $terms->name;

This is the code in the custom page template file.

$taxonomy_id = 'term id you got';
echo getTermsName($taxonomy_id);

Nothing happens.

I am quite bad at this; I hope in a very simple solution.


With Boriana we found out that the mythemename_preprocess function is not working not taking effect in my drupal. If anyone has idea why, that will be the key to this problem.

  • My original question got edited due to grammar mistakes, though the code has been edited as well. As of the edit, it still does not work... Commented Jul 10, 2012 at 16:54

1 Answer 1


If you're trying to use this in your page template files, then you should put your template.php code inside the yourtheme_preprocess_page(&$vars) function. That's the one that will get called before your page template file, and it can "communicate" its results to the template file by putting them in the $vars variable which was passed to it by reference.

So here's an idea of how you can improve your code:

In template.php:

function mytheme_preprocess_page(&$vars) {
  $term = taxonomy_get_term($taxonomy_id);
  $vars['term_name'] = $terms->name;     // Store anything you want to use later in $vars

In page.tpl:

<?php print $term_name; ?>

Let me know if that helps you get closer!

============================ EDIT =============

The variables set in the hook_preprocess_page() function are only available in your page.tpl files. If you're trying to get to these variables in your view templates, you'll have to instead use a views pre-processing function, such as mytheme_preprocess_views_view(&$vars)

  • I get this error in my apache log:[Tue Jul 10 19:09:27 2012] [error] [client] PHP Parse error: syntax error, unexpected T_VARIABLE in /var/www/web/sites/all/themes/htc/template.php on line 78 Commented Jul 11, 2012 at 15:52
  • So it's not finding the $term_name variable that you set in this line: "$vars['term_name'] $terms->name;"... Did you change the 'mytheme' part in the function to your theme name? You may not have realized that the pre-processing functions that to start with your theme name, and that was just a placeholder text for me... Commented Jul 11, 2012 at 16:11
  • I didi. It reads htc_preprocess_page(... .htc is my theme name. Commented Jul 11, 2012 at 16:16
  • I just edited my response to include some extra troubleshooting tips... Commented Jul 11, 2012 at 16:38
  • Based on example code I think the error in your previous code was missing the "=" from $vars['term_name'] $terms->name; so I changed it to: $vars['term_name'] = $terms->name; Now I get no error, but the problem is it does not echo anything under $term_name. I tried with the test code and its not printing $test NOR printing "TESTING" anywhere. Commented Jul 11, 2012 at 16:49

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.