I have a field (called Division) attached to a node. I want to print out a link (called Switch) on page.tpl.php that varies according to the value of this (node-based) field.

I can successfully do this with the following code:

In template.php

function elite_field_division_helper(&$variables) {
  if ($node = $variables['node']) {
    $field_division = field_get_items('node', $node, 'field_division');
    if ($field_division[0]['tid'] == 1) {
      $variables['switch_site'] = '<a id="switch_site" href="'.$GLOBALS['base_url'].'/business'.'">Visit Our Business Website</a>';
    else if ($field_division[0]['tid'] == 2) {
         $variables['switch_site'] = '<a id="switch_site" href="'.$GLOBALS['base_url'].'/home'.'">Visit Our At Home Website</a>';


In page.tpl.php

<?php if (!empty($switch_site)):?>
  <?php print $switch_site; ?>
<?php endif; ?>

My question is: How can I get this code to work with fields that are attached to TAXONOMY PAGES? (As Drupal 7 allows taxonomy pages to have fields).


1 Answer 1


Panels is very good for overriding Taxonomy pages. You can have different page and layout variants per vocabulary, user, theme, site etc. You can then include your code in a custom panel pane for taxonomy pages, together with whatever layout or views necessary, or write your own CTools content type for Panels.

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.