0
votes

I have a number of views on my website that use a taxonomy term as a contextual filter. I am trying to get that taxonomy term into the page title.

i.e.

'Latest TAXONOMY_TERM News | Sitename etc.'

I am using taxonomy_term_load in a THEME_views_post_render function in my template.php to fetch the term and build the page title. I am then passing this variable to the THEME_preprocess_html where I use it to override $variables['head_title'].

i.e.

views_post_render:

$term = taxonomy_term_load($view->result[0]->_field_data['nid']['entity']->field_term['und'][0]['tid']);

$page_title = 'Latest ' . $term->name . ' News | ' . variable_get('site_name', 'Sitename etc');

preprocess_html:

$variables['head_title'] = $page_title ;

If I echo out $variables['head_title'] I can see the page title I have defined in THEME_views_post_render but it is clearly missing the taxonomy term.

i.e.

'Latest News | Sitename etc.'

Can anyone throw any light on what's happening here? I did think about doing all the logic within the THEME_preprocess_html function, but this doesn't seem to have access to the view.

Any help gratefully appreciated.

Rob.

2

2 Answers

0
votes

In view title you can use replacement pattern which will present term-name. using this you can set required page title.

0
votes

You didn't provide how you are computing/filling the $view variable in your code snippet. Make sure first that you are getting that right. I'll also suggest using Devel module's dpm functionality (or its friends) instead of using echo for your debugging.