使用wp_insert_post作为起始页设置新页面

时间:2013-04-13 15:38:28

标签: php wordpress wordpress-theming

我正在创建一个带有Wordpress子主题的APP。在激活主题时,它具有使用wp_insert_post创建的起始页面。如何在 functions.php 中使用PHP将此页面设置为startpage

// Install theme
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
        $last_id = wp_insert_post(array(
            'post_type' => 'page',
            'post_title' => 'Welcome to this wonderful page!',
            'post_content' => 'Holy smoke',
            'post_name' => 'startpage',
            'post_status' => 'publish',
            'comment_status' => 'closed'
        ));
        update_post_meta($last_id, "_wp_page_template", "page.php");

// Set this page as startpage... but how? 

} // Install theme

1 个答案:

答案 0 :(得分:2)

如果理解正确,您正在搜索选项page_on_front

  

page on front

只需使用:

// Set "static page" as the option
update_option( 'show_on_front', 'page' );

// Set the front page ID
update_option( 'page_on_front', $last_id );
相关问题