2009-07-27 17 views
11

oluşturarak? Aşağıda http://codex.wordpress.org/Function_Reference/wp_insert_postWordPress - otomatik Nasıl otomatik (örneğin, eklenti etkinleştirildiğinde) bir WordPress sayfası oluşturmak için sayfayı

bakınız POST_TYPE: yanı sayfaları ekleyebilirsiniz

+0

tam olarak ne anlama geliyor? Wp çekirdek API'sini kullanarak bir sayfa oluşturan bir eklentiyi kodlamak ister misiniz? –

+0

evet, tam olarak bu. Yeni bir sayfa oluşturmak istiyorum, mevcut bir yeri bir yere eklemiyorum. – Phil

cevap

21

kullanın wp_insert_post().

$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

Çünkü Sayfalar, Sayfalar olarak işaretlenen İletilerdir. –

+0

Teşekkürler. Ben acemi dev soru eklentisi ... olacak bu marka sayfasını i eklentiyi etkinleştirmek veya i aktive oluyor anda o sayfayı yapmak eklentisi istediğiniz belirtmek için bazı kod eklemek gerektiğinde, aynı zamanda :) – Phil

+0

düşünce kolay? – Phil

-3

WordPress, veritabanı soyutlaması için wp-> sorgu API yöntemini sağlar. Gerektiğinde bir Sayfa oluşturmak için uygun sorguyu oluşturabilirsiniz.

+4

Bu genel olarak oldukça kötü bir öneridir. Sorguyu yalnızca bir API işleviyle aynı şekilde başaramazsanız kullanmalısınız. Gelecekte yapılan tablo değişiklikleri olmanın temel nedeni, fonksiyonlar umarız upkept iken, sorgularınızı kırabilir. –