Drupal 7:如何在添加内容时仅允许将子级别的分类项目选为类别

时间:2013-02-28 21:55:54

标签: drupal-7 drupal-taxonomy

我有一个内容类型,它有一个基于分类的类别字段。但我希望编辑只能为每个内容片段选择子类别,而不是父类别。我该怎么做?

1 个答案:

答案 0 :(得分:0)

我有类似于这个外观的代码,如果可能在某种程度上帮助你...如果你计划通过使用自定义模块来实现它,它会在数组中获取childs和parent ...

 $tree_type =  taxonomy_get_tree(3);
    $childs["selected"]="All";

    foreach($tree_type as $key =>$value) {
                $temp_ = taxonomy_term_load($value->parents[0]);           //IF parent is set already
            if($value->parents[0]==0) {                             //if no any parent taxonomy
                    if(is_object($temp_)==TRUE) {                 //CHECK IF SINGLE iTEM PARENT
                    if(isset($childs[$temp_->name])) {           //if array key is already set 
                            if(is_array($key)!=FALSE) {         //if value is not an array
                    $childs[$temp_->name][$tree_type[$key]->tid]=array($key=>$value->name);  // set the parent child array
                            }
                    }else {
                            if(is_array($key)!=FALSE) {    //if value is not an array
                    $childs[$temp_->name][$tree_type[$key]->tid]=array($key=>$value->name);  // set the parent child array
                            }
                        }
                    }else
                    {
                        $childs[$value->name]=array();
                        $childs[$value->name][$tree_type[$key]->tid]="-".$value->name;
                        //drupal_set_message("-------<pre>".$value->name."</pre>-------");
                        //drupal_set_message("<pre>".print_r($childs,true)."</pre>");
                        }
                }else {
        $childs[$temp_->name][$tree_type[$key]->tid]=$value->name;          //$childs[$temp_->tid]=$temp_->name;
                }
        }
相关问题