2009-07-27 34 views
11

¿Cómo crear automáticamente una página de WordPress (por ejemplo, cuando el complemento está activado)?WordPress - creando automáticamente la página

+0

¿Qué quieres decir exactamente? ¿Desea codificar un complemento que crea una página con la API wp core? –

+0

sí, exactamente eso. Quiero crear una nueva página, no insertar una existente en alguna parte. – Phil

Respuesta

21

Uso wp_insert_post(), que se puede insertar páginas así: http://codex.wordpress.org/Function_Reference/wp_insert_post

Ver post_type a continuación.

$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

Porque las páginas son simplemente publicaciones que están marcadas como páginas. –

+0

Gracias. Más fácil que pensé :) – Phil

+0

Además, la pregunta del desarrollador del complemento novato ... ¿hará esto una página cuando active el complemento o tengo que agregar un código para especificar que quiero el complemento para hacer esa página en el momento en que se activa? – Phil

-3

Wordpress proporciona el método wp-> query API para la abstracción de la base de datos. Puede crear la consulta adecuada para hacer una página cuando sea necesario.

+4

Esa es una sugerencia bastante mala en general. Debe usar la consulta solo si no puede lograr lo mismo con una función API. La razón principal por la cual los futuros cambios en la tabla pueden interrumpir su consulta, mientras que las funciones se mantienen optimizadas. –

Cuestiones relacionadas