深度阅读

"Drupal自动创建分类函数"

作者
作者
2023年08月22日
更新时间
7.3 分钟
阅读时间
0
阅读量

/ *Return the term id for a given term name.

自动创建分类*/

function _get_tid_from_term_name($term_name, $vocabulary = ‘tags’) {

// $vocabulary = ‘zhonglei’;

$arr_terms = taxonomy_get_term_by_name($term_name, $vocabulary);

if (!empty($arr_terms)) {

$arr_terms = array_values($arr_terms);

$tid = $arr_terms[0]->tid;

} else {

$vobj = taxonomy_vocabulary_machine_name_load($vocabulary);

$term = new stdClass();

$term->name = $term_name;

$term->vid = $vobj->vid;

taxonomy_term_save($term);

$tid = $term->tid;

}

return $tid;

}

https://gist.github.com/ba819e8190d51db1701c

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。