2

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

4

1 回答 1

0

我有类似于这种外观的代码,如果可能对您有所帮助...如果您打算通过使用自定义模块来实现它,它会将孩子和父母放在一个数组中...

 $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;
                }
        }
于 2013-08-25T10:44:23.040 回答