Last active
August 29, 2015 13:57
-
-
Save wesruv/9469693 to your computer and use it in GitHub Desktop.
Dynamic Drupal page preprocessors for taxonomies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TEMPLATE_preprocess_page(&$variables) { | |
// Set some vars for ease | |
$node = isset($variables['node']) ? $variables['node'] : ''; | |
$page = &$variables['page']; | |
// The good bit: | |
if(arg(0) == 'taxonomy') { | |
// Preprocess because it's a taxonomy | |
$function = __FUNCTION__ .'_taxonomy'; | |
if(function_exists($function)) { | |
$function($variables); | |
} | |
if(arg(1) == 'term') { | |
$tid = arg(2); | |
$term = taxonomy_term_load($tid); | |
$vocabulary = $term->vocabulary_machine_name; | |
$variables['term'] = $term; | |
// Preprocess because it's a term | |
$function = __FUNCTION__ .'_term'; | |
if(function_exists($function)) { | |
$function($variables); | |
} | |
// Preprocess because it's a term in a certain vocab | |
$function = __FUNCTION__ .'_term_'. $vocabulary; | |
if(function_exists($function)) { | |
$function($variables); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment