Posted By

JuliaKM on 08/31/07


Tagged

menu textmate drupal taxonomy


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

basicmagic
kellyharding
mmccrack
panatlantica


Drupal - case switch taxonomy


 / Published in: PHP
 

  1. function _phptemplate_variables($hook, $vars) {
  2. switch ($hook) {
  3.  
  4.  
  5. case 'page':
  6.  
  7. /* Get the taxonomy info from the current node while in the page */
  8. $node_taxonomy_object = $vars['node']->taxonomy;
  9. /* make sure the taxonomy object exists to prevent errors */
  10. if ($node_taxonomy_object) {
  11. foreach($node_taxonomy_object as $term) {
  12. /* only use selected vocabulary IDs to generate classes -- lists these below (1, and 21 are just examples) */
  13. switch($term->vid) {
  14. case 3:
  15. /*In Print*/
  16. $vars['body_id'] = 'media';
  17. $vars['body_class'] = 'in-print';
  18. break;
  19.  
  20. // case 1:
  21. /*Issues*/
  22. /* $vars['body_id'] = 'policy';
  23. $vars['body_class'] = 'issues';
  24. break; */
  25.  
  26. case 6:
  27. /*Multimedia*/
  28. $vars['body_id'] = 'media';
  29. $vars['body_class'] = 'multimedia';
  30. break;
  31.  
  32. case 2:
  33. /*Publication*/
  34. $vars['body_id'] = 'media';
  35. $vars['body_class'] = 'publication-archive';
  36. break;
  37.  
  38. case 9:
  39. /*Other Media*/
  40. $vars['body_id'] = 'media';
  41. $tempbody = str_replace(" ","-",$term->name);
  42. $vars['body_class'] = strtolower($tempbody);
  43. break;
  44.  
  45. case 10:
  46. /*Other Media*/
  47. $vars['body_id'] = 'outreach';
  48. $tempbody = str_replace(" ","-",$term->name);
  49. $vars['body_class'] = strtolower($tempbody);
  50. break;
  51.  
  52. case 11:
  53. /*Analysis*/
  54. $vars['body_id'] = 'analysis';
  55. $tempbody = str_replace(" ","-",$term->name);
  56. $vars['body_class'] = strtolower($tempbody);
  57. break;
  58.  
  59.  
  60. case 14;
  61. $test = arg(2);
  62. error_log($test);
  63.  
  64.  
  65. if (!arg(3)) {
  66. $id = $var['node']->nid;
  67. $terms = taxonomy_node_get_terms_by_vocabulary($id, 14);
  68.  
  69. foreach ($terms as $t) {
  70. $termID = $t->tid;
  71. $intBody = $t->name;
  72. }
  73.  
  74. //get parents
  75. $parents = taxonomy_get_parents($termID);
  76.  
  77. foreach ($parents as $parent){
  78. $vars['body_id']=$parent->name;
  79. }
  80.  
  81. $tempbody = str_replace(" ","-",$intBody);
  82. $vars['body_class'] = strtolower($intBody);
  83.  
  84. }
  85.  
  86.  
  87.  
  88. case 8:
  89. /* build the $body_class from the term's name, replacing spaces with "-" */
  90. $vars['body_id'] = str_replace(" ","-",$term->name);
  91. /* build the $body_ID from the term's vocabulary name, replacing spaces with "-"
  92.   $vocabulary_array = taxonomy_get_vocabulary($term->vid);
  93.   $vars['body_id'] = str_replace(" ","-",$vocabulary_array->name);*/
  94. break;
  95.  
  96. default:
  97. $tempbody = str_replace(" ","-",$term->name);
  98. $vars['body_id'] = strtolower($tempbody);
  99. $vars['body_class'] = 'none';
  100. }
  101.  
  102. }
  103. }
  104. break;
  105.  
  106.  
  107. }
  108. return $vars;
  109. }

Report this snippet  

You need to login to post a comment.