Skip to content

Instantly share code, notes, and snippets.

@wesruv
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesruv/9469693 to your computer and use it in GitHub Desktop.
Save wesruv/9469693 to your computer and use it in GitHub Desktop.
Dynamic Drupal page preprocessors for taxonomies
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