【问题标题】:Drupal 7: How to only allow child levels of taxonomy item to be chosen as category when adding contentDrupal 7:添加内容时如何只允许将分类项目的子级别选择为类别
【发布时间】:2013-02-28 21:55:53
【问题描述】:

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

【问题讨论】:

    标签: drupal-7 drupal-taxonomy


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多