put the code into the template.php file?
It's fine to put code in template.php, but do not print or echo there. All print or echo code should be in template files (.tpl.php). If you need to prepare variables for output in a template file, alter a preprocess function (eg. THEMENAME_preprocess_page if you need them in page.tpl.php), add your variables to the $variables array (eg. $variables['greeting'] = 'Hello!'; and print those variables in the template file (print $greeting;).

So for this example it would be something like:

function THEMENAME_preprocess_node(&amp;$variables) {
  $common = $variables['content']['body']['#object']-&gt;field_fenlei['zh-hans'];
  $term_links = '';
  foreach($common as $vocab){
    $term_links .= l($vocab['taxonomy_term']-&gt;name,$vocab['taxonomy_term']-&gt;uri['path']);
  } 
  $variables['fenlei_term_links'] = $term_links;
}


Now you can access the output with the variable $fenlei_term_links in your node.tpl.php:

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


In general you might want to use something like http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links or http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_items