且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式创建论坛主题?

更新时间:2023-02-12 19:15:24

以编程方式创建新节点的快速,安全和简便的方法是使用 node_save()

A quick, safe and easy way to create new nodes programmatically is to use node_save():

<?php
  // Construct the new node object.
  $node = new stdClass();

  // Set the values for the node
  $node->title = "My new forum topic";
  $node->body = "The body of my forum topic.\n\nAdditional Information";
  $node->type = 'forum';   // Your specified content type
  $node->created = time();
  $node->changed = $node->created;
  $node->status = 1;       // To have published, else use 0
  $node->promote = 1;      // If you want promoted to front page, else use 0
  $node->sticky = 0;
  $node->format = 1;       // Filtered HTML
  $node->uid = 1;          // UID of content owner
  $node->language = 'en';

  // If known, the taxonomy TID values can be added as an array.
  $node->taxonomy = array(2,3,1,);

  node_save($node);
?>