1

I am after a description which is similar for all taxonomy terms based on a schools location.

So I've created a few views based on continents at http://www.explorefreediving.com/freediving-schools-in-africa and then just added a description for that view and will be doing the same for the other continents.

"Improve your snorkeling, spearfishing and freediving with one of the many schools and freediving training courses held by apnea instructors across Africa."

I am now after a similar description for every country taxonomy term which is what I use to categorise the freedive schools.

So if you click on Egypt to the right when you are looking at Africa http://www.explorefreediving.com/school-location/africa/egypt you get sent to a taxonomy term and the same with other locations too

I want to be able to insert a description for the hundreds of taxonomy term school locations (countries) without having to manually do it? The most I know I could do is set up a description in each header and use tokens but is this the right approach? If it is, how do I do that exactly? I usually have problems with tokens and using the right ones.

If it is the right approach, doesn't that mean I will have that description across all taxonomy terms because the same view is used?

1

There are at least two ways to do this:

1. Views

In your views admin page, add a Global: Text area to header. Then check off Use replacement tokens from the first row. You can see the tokens (patterns) below under Replacement patterns. Your custom text my be like that:

"Improve your snorkeling, spearfishing and freediving with one of the many schools and freediving training courses held by apnea instructors across %1."

2. page--vocabulary--[machine-name].tpl.php

You could create a custom vocabulary tpl.php page and add your custom text. Details come from that answer:

  • Copy (and past) the page.tpl.php into your theme folder.

  • Rename it page--vocabulary--[machine name].tpl.php

(page--vocabulary--location.tpl.php etc.)

  • Open the template.php file in the theme folder and add this function:

Don't forget to change the THEME to your theme name and if you have already had the preprocess_page function in the template.php file and do not add the preprocess_page function again.

function THEME_preprocess_page(&$vars) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $term = taxonomy_term_load(arg(2));
    $vars['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name;
  }
}
  • Open the page--vocabulary--location.tpl.php file and find that line:

(Your theme's template.php file may be different but the main structure is the same.)

  • Then add what you want:

(with your css class, spans etc.)

<div class="term_description"
"Improve your snorkeling, spearfishing and freediving with one of the many schools and freediving training courses held by apnea instructors across <?php print $title; ?>."
</div>


- Clear all caches.

| improve this answer | |
  • herci the first one has worked really, well, didn't know I could add that to global text area in the header. Two problems though, This page has two global header messages now? and when i go to other taxonomy terms, they too have this description I only want for school-locations, would I have to clone the view and use that just for the school-locations? – Martin Dec 7 '14 at 20:38
  • You could combine header messages in one message. For other problem, I would prefer second way if the school-locations is a vocabulary. By second way you can customize each category, not all of them. – herci Dec 7 '14 at 20:49
  • What do you mean by 'have two descriptions'? Could you please add a screenshot? – herci Dec 9 '14 at 22:51
  • imgur.com/EM3Bo7Y – Martin Dec 9 '14 at 22:55
  • @Martin and what does your views header look like, please? (Views admin page screenshot) – herci Dec 9 '14 at 22:58
0

Herci I have added Taxonomy Views Intergrator https://www.drupal.org/project/tvi and it has worked like a charm now, so I can add a description to any taxonomy vocab I want now, use it across all of it's terms, with tokens too to mix it up and keep each one unique to the page it's on.

So this is a module solution and work around for your second way.

I still have two descriptions though...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.