立即保存以编程方式嵌套的分类术语
下面的代码允许使用 Drupal API 创建分类术语
$terms = array(
$term1 = array(
'name' => 'term name',
'description' => '',
'parent' => array(0),
'vid' => $vid,
),
$term2 = array(
'name' => 'term name',
'description' => '',
'parent' => array(0),
'vid' => $vid,
),
$term3 = array(
'name' => 'term name',
'description' => '',
'parent' => array(0),
'vid' => $vid,
),
);
foreach ($terms as $term) {
$term = (object) $term;
taxonomy_term_save($term);
}
它对于同级术语效果很好,但是如果我需要创建嵌套分类树怎么办?有一个“父”键应该包含父术语 ID 数组来执行此操作,
在将父术语保存到数据库中之前,我如何知道这些 ID?
the code below allows to create taxonomy terms using Drupal API
$terms = array(
$term1 = array(
'name' => 'term name',
'description' => '',
'parent' => array(0),
'vid' => $vid,
),
$term2 = array(
'name' => 'term name',
'description' => '',
'parent' => array(0),
'vid' => $vid,
),
$term3 = array(
'name' => 'term name',
'description' => '',
'parent' => array(0),
'vid' => $vid,
),
);
foreach ($terms as $term) {
$term = (object) $term;
taxonomy_term_save($term);
}
It working well for sibling terms but what if I need to create nester taxonomy tree? There is 'parent' key that should contain array of parent term ids to do that
How will I know these IDs before parent terms get saved in DB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该密钥通过
taxonomy_term_save
添加到传递的术语对象中(更具体地说,通过taxonomy_term_save
调用drupal_write_record
):The key is added to the passed term object by
taxonomy_term_save
(more specifically bytaxonomy_term_save
callingdrupal_write_record
):