Return to Snippet

Revision: 3686
at August 31, 2007 11:48 by JuliaKM


Initial Code
/*Change menu*/

/**
* Override menu links output
* NOTE: change function name to match theme name
**/


/*CHANGED Created body id based on section vocabulary */


//TODO Add is_front

function _phptemplate_variables($hook, $vars) {
    switch ($hook) {
           case 'page':

/*need to check for taxonomy or admin system flips out*/
   
	/* Get the taxonomy info from the current node while in the page */
      $node_taxonomy_object = $vars['node']->taxonomy;
     if ($node_taxonomy_object) {
					foreach ($node_taxonomy_object as $tax_object) {
						$vid = $tax_object->vid;
				
		switch($tax_object->vid){
	
		case 14:
		#works for primary navigation like mysite.com/about/		
		
		if (!arg(3) && !arg(2) ) {
					$id = $vars['node']->nid;
						$terms = taxonomy_node_get_terms_by_vocabulary($id, $vid);
		
						foreach ($terms as $term) {
							$termID = $term->tid;
							$body_id = $term->name; 
						}
					
				$parentCheck = taxonomy_get_parents($termID);
							if ($parentCheck == NULL){
								$vars['body_class'] = 'noselect';	
							}
							
					$body_id = strtolower($body_id);
					$vars['body_id'] = str_replace(" ","-",$body_id);
					
				
			
		}
							
		#Works for second-level navigation like mysite.com/about/mission/  
				if (!arg(3)) {
						$id = $vars['node']->nid;
						$terms = taxonomy_node_get_terms_by_vocabulary($id, $vid);
		
						foreach ($terms as $term) {
							$termID = $term->tid;
							$body_class = $term->name; 
						}
		

				//get parents		
						$parents = taxonomy_get_parents($termID);
		
						foreach ($parents as $parent){
							$body_id=$parent->name;
						}
	
					$body_class = strtolower($body_class);
					$vars['body_class'] = str_replace(" ","-",$body_class);
			
					$body_id = strtolower($body_id);
					$vars['body_id'] = str_replace(" ","-",$body_id);
					
			
			#account for having no parents, really redundant, needs to be shortened.		
					$parentCheck = taxonomy_get_parents($termID);
						if ($parentCheck == NULL){
					$vars['body_class'] = 'noselect';	
							}
							
								
			}
		
		# No third-level navigation on static pages
	
		
			break;

#designed for non-static pages, pages not set as "Pages"	

			default:
#works for primary navigation like mysite.com/about/			


	$vocab = taxonomy_get_vocabulary($vid);

	$body_id = $vocab->name;
	
					
			$body_id = strtolower($body_id);
			$vars['body_id'] = str_replace(" ","-",$body_id);
					
	
		if (!arg(3) && !arg(2)) {		
					$vars['body_class'] = 'noselect';
		}
		
		               
# Works for second-level navigation like mysite.com/about/mission/  
				if (!arg(3)) {
						$id = $vars['node']->nid;
						$terms = taxonomy_node_get_terms_by_vocabulary($id, $vid);
		
						foreach ($terms as $term) {
							$termID = $term->tid;
							$body_class = $term->name; 
						}
	
					$body_class = strtolower($body_class);
					$vars['body_class'] = str_replace(" ","-",$body_class);
	
			}
	

# Works for third-level navigation like mysite.com/about/mission/article.html
				if (arg(3)) {
						$id = $vars['node']->nid;
						$terms = taxonomy_node_get_terms_by_vocabularies($id, $vid);
		
						foreach ($terms as $term) {
							$termID = $term->tid;
							$body_class = $term->name; 
						}
		
	
					$body_class = strtolower($body_class);
					$vars['body_class'] = str_replace(" ","-",$body_class);
					//echo "Body Class =" . $body_class;

								
			}
	
		}
	}
   }
   return $vars;
  }
}

Initial URL


Initial Description


Initial Title
drupal taxonomy based menu

Initial Tags
textmate, drupal

Initial Language
PHP