在 WordPress 中自动创建页面 [英] Automatically create page in WordPress

查看:27
本文介绍了在 WordPress 中自动创建页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自动创建 WordPress 页面(例如,当插件被激活时)?

How can I automatically create a WordPress page (for example, when plugin is activated)?

推荐答案

使用 wp_insert_post(),也可以插入页面:http://codex.wordpress.org/Function_Reference/wp_insert_post

Use wp_insert_post(), which can insert pages as well: http://codex.wordpress.org/Function_Reference/wp_insert_post

请参阅下面的 post_type.

See post_type below.

$post = array(
  'ID' => [ <post id> ] //Are you updating an existing post?
  'menu_order' => [ <order> ] //If new post is a page, sets the order should it appear in the tabs.
  'page_template' => [ <template file> ] //Sets the template for the page.
  'comment_status' => [ 'closed' | 'open' ] // 'closed' means no comments.
  'ping_status' => [ ? ] //Ping status?
  'pinged' => [ ? ] //?
  'post_author' => [ <user ID> ] //The user ID number of the author.
  'post_category' => [ array(<category id>, <...>) ] //Add some categories.
  'post_content' => [ <the text of the post> ] //The full text of the post.
  'post_date' => [ Y-m-d H:i:s ] //The time post was made.
  'post_date_gmt' => [ Y-m-d H:i:s ] //The time post was made, in GMT.
  'post_excerpt' => [ <an excerpt> ] //For all your post excerpt needs.
  'post_name' => [ <the name> ] // The name (slug) for your post
  'post_parent' => [ <post ID> ] //Sets the parent of the new post.
  'post_password' => [ ? ] //password for post?
  'post_status' => [ 'draft' | 'publish' | 'pending' ] //Set the status of the new post.
  'post_title' => [ <the title> ] //The title of your post.
  'post_type' => [ 'post' | 'page' ] //Sometimes you want to post a page.
  'tags_input' => [ '<tag>, <tag>, <...>' ] //For tags.
  'to_ping' => [ ? ] //?
);  

// Insert the post into the database
wp_insert_post( $post );

这篇关于在 WordPress 中自动创建页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆