我在发布Drupal 7核心博客模块时有一个问题。
你能给我一个简单的例子(PHP代码或MySQL查询)如何添加一个博客帖子:
Title="Blog post title"
Post content="Content".
我需要一个PHP或MySQL的例子。我不想在主页上发帖
通过在模块文件中编写以下代码以编程方式创建它
$text_body = 'Your node body text';
$node = new stdClass(); // Create a new node object
$node->type = 'blog'; // Content type
$node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
node_object_prepare($node); //Set some default values
$node->title = 'Your node title';
$node->body[$node->language][0]['value'] = $text_body;
$node->body[$node->language][0]['summary'] = text_summary($text_body);
$node->body[$node->language][0]['format'] = 'full_html';
$node->status = 1; // (1 or 0): published or unpublished
$node->promote = 0; // (1 or 0): promoted to front page or not
$node->sticky = 0; // (1 or 0): sticky at top of lists or not
$node->comment = 1; // 2 = comments open, 1 = comments closed, 0 = comments hidden
// Add author of the node
$node->uid = 1;
// Set created date
$node->date = 'complaint_post_date';
$node->created = strtotime('complaint_post_date');
$path = 'content/blog-' . date('YmdHis');
$node->path = array('alias' => $path);
// Save the node
node_save($node);