2014-11-26 6 views
0

Моя проблема заключается в том, что пользователи создают новые страницы с контентом и работают хорошо и по назначению. То, что они должны сделать, это добавить другую страницу без содержимого, выбрать правильный шаблон и сделать его родителем только что созданной страницы. Вторая пустая страница есть, так как она дает пользователю просмотр веб-страницы для просмотра содержимого по-другому, чем на главной странице. Есть ли способ, которым Wordpress может автоматически добавить эту пустую страницу в эти шаблоны?Wordpress - Как автоматически создать дочернюю страницу

Вот как структура страницы работает

Главная страница -> Wordpress страницы (созданные пользователем) -> Wordpress страницы (списки того же содержания, что и родительской страницы, но в другом формате Это заготовка. страница, созданная пользователем wordpress.)

Итак, есть способ автоматически создать эту дополнительную подстраницу или есть способ добавить этот код и ссылку на исходный шаблон страницы Wordpress?

Спасибо, Райан

ответ

0

Вы можете добавить действие после того, как опубликовать страницу. В этом действии вы можете добавить новую страницу со свойствами.

Вы можете попробовать это:

function on_page_publish($ID, $post) { 

    $my_post = array(
     'post_title' => 'My post', 
     'post_content' => 'This is my post.', 
     'post_status' => 'publish', 
     'post_author' => 1, 
    ); 

    // Insert the post into the database 
    wp_insert_post($my_post); 

} 
add_action( 'publish_page', 'on_page_publish', 10, 2); 

Работа будет полезна всем доступна здесь:

$post = array(
    'ID'    => [ <post id> ] // Are you updating an existing post? 
    'post_content' => [ <string> ] // The full text of the post. 
    'post_name'  => [ <string> ] // The name (slug) for your post 
    'post_title'  => [ <string> ] // The title of your post. 
    'post_status' => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ] // Default 'draft'. 
    'post_type'  => [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ] // Default 'post'. 
    'post_author' => [ <user ID> ] // The user ID number of the author. Default is the current user ID. 
    'ping_status' => [ 'closed' | 'open' ] // Pingbacks or trackbacks allowed. Default is the option 'default_ping_status'. 
    'post_parent' => [ <post ID> ] // Sets the parent of the new post, if any. Default 0. 
    'menu_order'  => [ <order> ] // If new post is a page, sets the order in which it should appear in supported menus. Default 0. 
    'to_ping'  => // Space or carriage return-separated list of URLs to ping. Default empty string. 
    'pinged'   => // Space or carriage return-separated list of URLs that have been pinged. Default empty string. 
    'post_password' => [ <string> ] // Password for post, if any. Default empty string. 
    'guid'   => // Skip this and let Wordpress handle it, usually. 
    'post_content_filtered' => // Skip this and let Wordpress handle it, usually. 
    'post_excerpt' => [ <string> ] // For all your post excerpt needs. 
    '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. 
    'comment_status' => [ 'closed' | 'open' ] // Default is the option 'default_comment_status', or 'closed'. 
    'post_category' => [ array(<category id>, ...) ] // Default empty. 
    'tags_input'  => [ '<tag>, <tag>, ...' | array ] // Default empty. 
    'tax_input'  => [ array(<taxonomy> => <array | string>) ] // For custom taxonomies. Default empty. 
    'page_template' => [ <string> ] // Requires name of template file, eg template.php. Default empty. 
); 
Смежные вопросы