1

How can I display a taxonomy term in the url [example.com/taxonomy/% (% being the term)] of a page as title for that page - no view involved?

I assume it will require a block with some PHP or some hacking of a template.

In either case, what's the PHP and where do I put it?

I use D7 and Bartik.

Thanks. :)

2 Answers 2

1

Taxonomy Title is the only module that let's you control that title individually for every term. (You can also override the title generally by using a view or a pannel.) An additional "Taxonomy Term Page - heading" field wil appear on the taxonomy term edit form, allowing administrators to configure a specific heading for each term page.

The taxonomy title module also provides tokens which can be used in conjunction with the Page title and Meta tags modules.

This module was designed to update the heading tag at the top of the taxonomy term page. The contents of this H1 (or sometimes H2) tag are extremely important for SEO (Search Engine Optimization). People interested in SEO may prefer to add more user-friendly, keyword-rich, and descriptive words to this heading element.

1

Another approach: override default taxonomy term display callback and do whatever you want with $term object. For ex., how do I usually do this with taxonomy_override module: 1. Define callback:

function MODULENAME_taxonomy_override_define_callback() {
  return array('my_term_display_callback' => 'Display Callback');
}

and callback itself:

function my_term_display_callback($term) {

  //Title display. DO WHATEVER YOU WANT
  drupal_set_title($term->name);
  //or
  drupal_set_title($term->tid);
  //or
  drupal_set_title($term->vid);
  //or
  drupal_set_title($term->tid . ' -> ' . $term->name);
  //...


  // Build breadcrumb based on the hierarchy of the term.
  $current = (object) array(
    'tid' => $term->tid,
  );

  $breadcrumb = array();
  while ($parents = taxonomy_get_parents($current->tid)) {
    $current = array_shift($parents);
    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
  }

  $breadcrumb[] = l(t('Home'), NULL);
  $breadcrumb = array_reverse($breadcrumb);
  $breadcrumb[] = '<span>' . $term->name . '</span>';
  drupal_set_breadcrumb($breadcrumb);

  // Set the term path as the canonical URL to prevent duplicate content.
  $uri = entity_uri('taxonomy_term', $term);
  drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
  // Set the non-aliased path as a default shortlink.
  drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);
  // usual part of term ends



  // DISPLAY.. DO WHATEVER YOU WANT
  if(someKindOfCheck) {
    return views_embed_view('viewName', 'blockOrPage');
  }
  elseif(anotherCheck) {
    return views_embed_view('viewName', 'blockOrPageWitchArgument', $term->tid);
  }
  else {
    return render(someRenderArray);
  }
}

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.