Jak automatycznie utworzyć stronę WordPress (na przykład, gdy wtyczka jest aktywowana)?WordPress - automatyczne tworzenie strony
Odpowiedz
Zastosowanie wp_insert_post()
, który można włożyć stron, a także: http://codex.wordpress.org/Function_Reference/wp_insert_post
widoczny post_type poniżej.
$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);
Ponieważ strony są po prostu wiadomościami oznaczonymi jako strony. –
Dzięki. Łatwiejsze, o czym pomyślałem :) – Phil
Co więcej, pytanie o wtyczkę dla początkujących ... czy to spowoduje, że strona po aktywowaniu wtyczki lub muszę dodać jakiś kod, aby określić, że chcę wtyczkę, aby ta strona była aktywowana w momencie jej aktywacji? – Phil
Wordpress udostępnia metodę API wp-> zapytania dla abstrakcji baz danych. Możesz utworzyć odpowiednie zapytanie, aby utworzyć stronę w razie potrzeby.
To całkiem niezła sugestia. Powinieneś używać zapytania tylko wtedy, gdy nie możesz osiągnąć tego samego z funkcją API. Główny powód przyszłych zmian w tabeli może przerwać twoją kwerendę, podczas gdy funkcje są miejmy nadzieję upkept. –
co masz na myśli? Czy chcesz zakodować wtyczkę, która tworzy stronę za pomocą interfejsu API wp core? –
tak, dokładnie to. chcę stworzyć NOWY STRONĘ, a nie wstawiać już istniejącego. – Phil