Change logo based on taxonomy term

I'm trying to change the logo in my header based on the taxonomy term of a page. I have managed to get it working on the taxonomy landing page itself. However, I have content pages that have term references on them which don't pull through the term title.

This the code that allowing me to display the title on the taxonomy page:

$termid = arg(2);       $term = taxonomy_term_load($termid);       $title = $term->name;        $title = str_replace(' ', '', $title);        $field_organisation->field_organisation['und'][0]['tid']; 

I am then stripping out the whitespace and printing the value inside an img tag.

I've tried doing this with views and creating a list of all nodes and adding a contextual filter. Yet this seems to only work the other way. So it only displays the image on the node page itself and NOT the taxonomy landing page.

Any help would be much appreciated.



You can make the code work in 2 situations.

$term = menu_get_object('taxonomy_term', 2);
if (empty($term)) {
  $node = menu_get_object('node', 1);
  $wrapper = entity_metadata_wrapper('node', $node);
  $term = $wrapper->field_organisation->value();

$title = $term->name;
$title = str_replace(' ', '', $title);

entity_metadata_wrapper() is the function provided by module Entity

Category: views Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.210 (s). 12 q(s)