Return to Snippet

Revision: 3685
at August 31, 2007 06:54 by JuliaKM


Initial Code
function _phptemplate_variables($hook, $vars) {
    switch ($hook) {
	

	           case 'page':

/* Get the taxonomy info from the current node while in the page */
                $node_taxonomy_object = $vars['node']->taxonomy;
/* make sure the taxonomy object exists to prevent errors */
                if ($node_taxonomy_object) {
                    foreach($node_taxonomy_object as $term) {
/* only use selected vocabulary IDs to generate classes -- lists these below (1, and 21 are just examples) */
                        switch($term->vid) {
                            case 3:
							/*In Print*/
							$vars['body_id'] = 'media';
							$vars['body_class'] = 'in-print';
 							break;

						//	case 1:
							/*Issues*/
                          /*  $vars['body_id'] = 'policy';
							$vars['body_class'] = 'issues';
							break; */
							
							case 6:
							/*Multimedia*/
                            $vars['body_id'] = 'media';
							$vars['body_class'] = 'multimedia';
							break;
							
							case 2:
							/*Publication*/
                            $vars['body_id'] = 'media';
							$vars['body_class'] = 'publication-archive';
							break; 
							
							case 9:
							/*Other Media*/
                            $vars['body_id'] = 'media';
							$tempbody = str_replace(" ","-",$term->name);
							$vars['body_class'] = strtolower($tempbody);
							break;
							
							case 10:
							/*Other Media*/
                            $vars['body_id'] = 'outreach';
							$tempbody = str_replace(" ","-",$term->name);
							$vars['body_class'] = strtolower($tempbody);
							break;
					
							case 11:
							/*Analysis*/
                            $vars['body_id'] = 'analysis';
							$tempbody = str_replace(" ","-",$term->name);
							$vars['body_class'] = strtolower($tempbody);
							break;
							
							
							case 14;
							$test = arg(2);			
							error_log($test);
							
							
							if (!arg(3)) {
									$id = $var['node']->nid;
									$terms = taxonomy_node_get_terms_by_vocabulary($id, 14);
		
										foreach ($terms as $t) {
											$termID = $t->tid;
											$intBody = $t->name; 
										}
		
										//get parents		
									$parents = taxonomy_get_parents($termID);
		
										foreach ($parents as $parent){
											$vars['body_id']=$parent->name;
										}
	 			
								$tempbody = str_replace(" ","-",$intBody);
								$vars['body_class'] = strtolower($intBody);
		
							}


							
							case 8:
/* build the $body_class from the term's name, replacing spaces with "-" */
                                $vars['body_id'] = str_replace(" ","-",$term->name);
/* build the $body_ID from the term's vocabulary name, replacing spaces with "-" 
                                $vocabulary_array = taxonomy_get_vocabulary($term->vid);
                                $vars['body_id'] = str_replace(" ","-",$vocabulary_array->name);*/
                            break;

							default:
							$tempbody = str_replace(" ","-",$term->name);
							$vars['body_id'] = strtolower($tempbody);
						    $vars['body_class'] = 'none';
                        }

                    }
                }
            break;
					

   }
   return $vars;
  }

Initial URL


Initial Description


Initial Title
Drupal - case switch taxonomy

Initial Tags
textmate, drupal

Initial Language
PHP