简体   繁体   中英

How to post to blog module on Drupal 7 by PHP or MySQL?

I have a problem with posting to Drupal 7 core blog module.

Can you give me a simple example (PHP code or MySQL query) how to add a blog post where:

Title="Blog post title"
Post content="Content".

I need a PHP or MySQL example. I don't want to post on home page.

create it programatically by writing this code in your module file

 $text_body = 'Your node body text'; $node = new stdClass(); // Create a new node object $node->type = 'blog'; // Content type $node->language = LANGUAGE_NONE; // Or eg '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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM