PHP 基于drupal分类法的菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 基于drupal分类法的菜单相关的知识,希望对你有一定的参考价值。

/*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;
  }
}

以上是关于PHP 基于drupal分类法的菜单的主要内容,如果未能解决你的问题,请参考以下文章

Drupal 分类菜单 - 让它与视图一起工作

HTML Drupal - 建立分类学菜单

Drupal-构建分类菜单

PHP Drupal - 案例转换分类法

php Drupal 7:获取分类法节点计数

PHP Drupal菜单不是链接的项目