WordPress - 自动创建页面
答
使用wp_insert_post()
,可插入网页,以及:http://codex.wordpress.org/Function_Reference/wp_insert_post
见下文post_type。
$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);
+1
因为页面只是标记为页面的帖子。 – 2009-07-27 01:12:13
答
WordPress的提供了数据库抽象的wp->查询API方法。您可以创建适当的查询以在需要时创建页面。
你是什么意思?你想编写一个使用wp核心API创建页面的插件吗? – 2009-07-27 01:06:51
是的,就是这样。我想创建NEW页面,而不是在某处插入现有的页面。 – Phil 2009-07-27 13:26:26