HTML Drupal - 建立分类学菜单

Posted

tags:

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

<?php
if (arg(0) == 'taxonomy' && arg(1)=='term' && is_numeric(arg(2))) {
  $terms = taxonomy_get_term(arg(2));

}
?>

<pre><?php echo $terms->name ?></pre>
<pre><?php echo arg(0); ?></pre>
<pre><?php echo arg(1); ?></pre>
<pre><?php echo arg(2); ?></pre>

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

以上是关于HTML Drupal - 建立分类学菜单的主要内容,如果未能解决你的问题,请参考以下文章

PHP 基于drupal分类法的菜单

Drupal-构建分类菜单

基于drupal分类法的菜单

添加菜单链接Drupal 8

Drupal创建自定义表单,上传文件代码

如何在Drupal7中用代码批量创建节点评论和分类