drupaldrupal-7drupal-themingdrupal-taxonomy

Drupal 7. Taxonomy. Term name override


I have vocabulary Angle, with terms: 10, 15, 20 etc. I want to have taxonomy page h1 title "Angle $term_name mm" - Angle 10mm, Angle 15mm.. Please push me on the right way or just help.


Solution

  • If you are not using modules like Panels or Views to show taxonomy terms, you may implement hook_preprocess_taxonomy_term() in your theme:

    function mytheme_preprocess_taxonomy_term(&$variables) {
      $term = $variables['term'];
      // Alter only terms of Angle vocabulary.
      if ($term->vocabulary_machine_name == 'angle') {
        // Alter only taxonomy term pages, not listings.
        if ($variables['page']) {
          $name = t('Angle @name mm', array('@name' => $term->name));
          drupal_set_title($name);
        }
      }
    }
    

    P.S. Why not using correct term names from the start? If you need raw angle values (10, 15 etc.) you may add corresponding numeric field to your vocabulary.