Preprocess taxonomy for a custom template file
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(&amp;$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(&amp;$vars) {
  $term = taxonomy_get_term($taxonomy_id);
  $vars['term_name'] = $terms-&gt;name;     // Store anything you want to use later in $vars
}


In page.tpl:

&lt;?php print $term_name; ?&gt;


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(&amp;$vars)