0

我是 drupal 的新手,我需要在我的 .install 自定义模块文件中创建一个分类,并将这个分类分配给特定的内容类型。知道怎么做吗?谢谢 !

4

1 回答 1

2

我假设“创建分类法”是指“创建分类法词汇”。如果是这种情况,您需要填充一个数组,例如:

  $vocabulary = array(
      'name' => t('<VOCABULARY_NAME>'),
      'multiple' => 0, // or 1, if you need multiple terms associated to any single node
      'required' => 0,  // or 1, if the association is required
      'hierarchy' => 1, // or 0, if is a tag-like term
      'relations' => 0,
      'module' => '<YOUR_MODULE_NAME>',
      'weight' => 0,
      'nodes' => array('<YOUR_NODE_TYPE>' => 1),
    );

并通过发出来保存词汇

** 编辑 **

$ret = taxonomy_save_vocabulary($vocabulary);

如果$ret == 1您正确保存了您的词汇,并且$vocabulary['vid']将拥有新创建的词汇的视频。如果要向其中添加术语,请创建数组:

$term = array(
  'vid' => <VOCABULARY_VID>,
  'name' => "<TERM NAME>",
  'description' => "An optional description for the term",
  'weight' => <AN_INTEGER_OPTIONAL_VALUE_FOR_WEIGHT>,
);
$ret = taxonomy_save_term($term);

并且 $ret 将再次设置为您保存操作的状态值,并且 $term['tid'] 将是新术语的术语 ID。

于 2013-10-20T14:49:12.293 回答