2009-07-27 89 views
11

如何自動創建一個WordPress頁面(例如,當插件被激活時)?WordPress - 自動創建頁面

+0

你是什麼意思?你想編寫一個使用wp核心API創建頁面的插件嗎? – 2009-07-27 01:06:51

+0

是的,就是這樣。我想創建NEW頁面,而不是在某處插入現有的頁面。 – Phil 2009-07-27 13:26:26

回答

21

使用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

-3

WordPress的提供了數據庫抽象的wp->查詢API方法。您可以創建適當的查詢以在需要時創建頁面。