PHP Drupal - 案例转换分类法

Posted

tags:

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

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

以上是关于PHP Drupal - 案例转换分类法的主要内容,如果未能解决你的问题,请参考以下文章

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

Drupal 8 相当于分类术语转换为术语 id 视图

php 从Drupal 8节点的分类术语中加载面包屑

php 查找由父项(Drupal 7)限制的分类学术语子(按名称)。

将 SQL 查询转换为 Drupal 7 PHP 规则

Drupal,视图:标头不接受 PHP