为多站点设置要加载的默认页面模板

时间:2011-12-12 作者:petergus

我正在修改install.php (从中压顶upgrade.php) 已注册用于加载使用新博客创建的默认页面的文件。

我正在尝试找出如何指定将分配给新页面的页面模板。

有类似的吗page_template =>? 我在抄本上搜索了一下,但似乎什么也没找到,或者我的语法想法不对。

默认情况下,当前页面代码为:

  $first_page = sprintf( __( "This is an example page. As a new WordPress user, you should go to <a href=\\"%s\\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() );

  if ( is_multisite() )
        $first_page = get_site_option( \'first_page\', $first_page );

  $first_post_guid = get_option(\'home\') . \'/?page_id=2\';
    $wpdb->insert( $wpdb->posts, array(
                                \'post_author\' => $user_id,
                                \'post_date\' => $now,
                                \'post_date_gmt\' => $now_gmt,
                                \'post_content\' => $first_page,
                                \'post_excerpt\' => \'\',
                                \'post_title\' => __( \'Sample Page\' ),
                                /* translators: Default page slug */
                                \'post_name\' => __( \'sample-page\' ),
                                \'post_modified\' => $now,
                                \'post_modified_gmt\' => $now_gmt,
                                \'guid\' => $first_post_guid,
                                \'post_type\' => \'page\',
                                \'to_ping\' => \'\',
                                \'pinged\' => \'\',
                                \'post_content_filtered\' => \'\'
                                ));
    $wpdb->insert( $wpdb->postmeta, array( \'post_id\' => 2, \'meta_key\' => \'_wp_page_template\', \'meta_value\' => \'default\' ) );

1 个回复
最合适的回答,由SO网友:Innate 整理而成

我认为没有类似page\\u template=>的内容,但您可以这样指定模板:

update_post_meta($id, "_wp_page_template", "new_template.php");
http://codex.wordpress.org/Function_Reference/update_post_meta或者使用上面的代码:

$wpdb->insert( $wpdb->postmeta, array( \'post_id\' => 2, \'meta_key\' => \'_wp_page_template\', \'meta_value\' => \'new_template.php\' ) );

结束

相关推荐

WordPress MultiSite的不同用途

有没有办法使用WordPress Multisite将所有子网站协作到主站点?我的想法是让所有子网站都成为一个组织的部门,主网站成为该组织的头版。导航将自动创建:一个用于主站点,然后一个单独的导航将列出部门(子站点)以及这些站点页面的下拉列表。我相信这一切都可以通过脚本来实现,但我很好奇是否有现成的解决方案。