1

我正在从 xml 自动创建节点,我需要为它们设置创建日期。我试过了

<?php 
   ...
   $node->created = $date //<- unix timestamp, $node is my node object
   $node->changed = $other_date; 
   ...
?>

但没有运气,它设置了当前日期。有任何想法吗?谢谢

-编辑-

$newNode = (object) NULL;
$newNode->type = 'blog';
$newNode->title = $title;
$newNode->uid = 1;
$newNode->status = 1;
$newNode->comment = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;
$newNode->body['und'][0] = array(
                                'value' => $body,
                                'format' => 'full_html');
$newNode->log      = 'Auto Imported Node';
$newNode->language = LANGUAGE_NONE;

// add fields
$newNode->field_description[LANGUAGE_NONE][0]['value'] = $description;
$newNode->field_byline[LANGUAGE_NONE][0]['value'] = $byline;
$newNode->field_small_image[LANGUAGE_NONE][0]['value'] = $smallimg;
$newNode->field_large_image[LANGUAGE_NONE][0]['value'] = $largeimg;


// save node
$newNode->created = $pd; // i've tried with commenting this line out, too
$newNode->date = $pd;
node_save($newNode);
4

2 回答 2

2

它应该适用于$node->created,但$node->changed不能使用 Drupal API 进行设置。

如果您使用的是用于设置的node_submit()函数,则需要设置为字符串日期。 strtotime($node->date)$node->created$node->date

$node->date = $date_string;
于 2012-05-23T15:05:49.910 回答
0

@Zoltan:谢谢,你是对的!当我使用:

$node->date = '2005-05-06 08:17:27';
node_save($node);

我保存后得到:

[created] => current timestamp
[changed] => current timestamp

但是在 node_save 之前添加行时:

$node = node_submit($node);

我保存后得到:

[created] => 1115360247
[changed] => current timestamp

并且在节点页面上会显示“创建”日期

于 2012-06-01T19:43:07.357 回答