【问题标题】:How to attach image and tag with the node如何使用节点附加图像和标签
【发布时间】:2010-08-26 16:03:13
【问题描述】:

我正在做一个将 XML 内容导入 Drupal 7 的项目。我已经用 PHP 解析了所有数据。

到目前为止,我已成功导入节点正文及其标题。 Drupal 7 没有关于如何将图像附加到节点和标签的文档。我真的需要帮助,因为我花了两天时间试图找到解决方案。如果有人提出解决方案,我将不胜感激。请引导我到某个地方。

function make_nodes($nodes) {
  $new_node = $nodes[0];
  $node = new stdClass();
  $node->title = $new_node['title'];
  $node->body['und'][0]['value'] = $new_node['body'];
  $node->type = 'article';
  $node->created = $new_node['timestamp'];
  $node->changed = $new_node['timestamp'];
  $node->status = 1;
  $node->promote = 1;
  $node->sticky = 0;
  $node->body['und'][0]['format'] = 1;
  $node->uid = (isset($local_user->uid) && !empty($local_user->uid)?$local_user->uid:1);
  $node->language = 'en';
  $node->timestamp = $new_node['timestamp'];
  $node->revision = 0;
  node_submit($node);
  node_save($node);
}

【问题讨论】:

标签: drupal drupal-7


【解决方案1】:

您需要将ImageField 添加到您的内容类型。这是 Drupal 6 中的一个单独模块,但在 Drupal 7 中移入核心。模块页面上链接了一些导入脚本,但 API 可能在 Drupal 7 中发生了变化。

您还可以查看Migrate module,它提供了用于导入 Drupal 的框架。

【讨论】:

  • 嗨。 drupal 7中的文章内容类型中已经有ImageField。这就是我要保存链接到节点的图像的地方。
  • Field API (api.drupal.org/api/group/field/7) 中应该有一个功能,但这是在 Drupal 7 中发生很大变化的区域,Drupal 6 方式将不再适用。
  • 那是真的,我已经尝试过 drupa 6 方式......它不起作用......我要去尝试一些东西,看到节点的主体也是一个字段,所以我像节点一样访问它->body['und'][0]['value'] = $new_node['body'];这就是如何访问drupal 7中的字段,所以它让我想到我也可以访问图像字段和标签字段,就像可能类似的方式 node->field_tags['und'][0]['value'] = 'something';我不确定,但它的东西
【解决方案2】:

嗨。在阅读了 10 个小时的文档后,我终于做到了……我在这里包含了我的代码

$uri = 'bird/bird_image.jpg';
$files =  new stdClass();
$files->uid = (isset($local_user->uid) && !empty($local_user->uid)?$local_user->uid:1);
$files->filename = 'bird.jpg';
$files->uri = $uri; 
$files->filemime = file_get_mimetype($uri);
$files->status = 1;
$files->timestamp = $new_node['timestamp'];

file_copy($files);

这就是上传文件和drupal 7数据库的方式

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多