使您$default_pages
数组是关联的数组,其中键是页面标题,值是页面内容。然后修改foreach循环以获取$key => $value
配对并将其用于wp_insert_post
作用像这样:
function default_pages( $blog_id )
{
$default_pages = array(
\'Contact\' => "This is your \'Contact\' page. Enter in your content here.",
\'Information\' => "This is your \'Information\' page. Enter in your content here.",
\'About\' => "This is your \'About\' page. Enter in your content here.",
\'Home\' => "This is your \'Home\' page. Enter in your content here.",
);
switch_to_blog( $blog_id );
if ( $current_pages = get_pages() )
$default_pages = array_diff( $default_pages, wp_list_pluck( $current_pages, \'post_title\' ) );
foreach ( $default_pages as $page_title => $page_content ) {
$data = array(
\'post_title\' => $page_title,
\'post_content\' => $page_content,
\'post_status\' => \'publish\',
\'post_type\' => \'page\',
);
wp_insert_post( add_magic_quotes( $data ) );
}
restore_current_blog();
}
add_action( \'wpmu_new_blog\', \'default_pages\' );