WordPress多站点上默认页面的不同页面内容

时间:2013-10-04 作者:Laura

我有一段代码,在Wordpress MU上安装的每个新站点上设置4个默认页面。我想知道如何为这四个页面中的每一个设置不同的“post\\u内容”?

<小时>

function default_pages( $blog_id )
{
$default_pages = array(
    \'Contact\',
    \'Information\',
    \'About\',
    \'Home\',
);

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 ) {        
    $data = array(
        \'post_title\'   => $page_title,
        \'post_content\' => "This is your \'$page_title\' page. Enter in your content here.",
        \'post_status\'  => \'publish\',
        \'post_type\'    => \'page\',
    );

    wp_insert_post( add_magic_quotes( $data ) );
}

restore_current_blog();
}

add_action( \'wpmu_new_blog\', \'default_pages\' );

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

使您$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\' );

结束

相关推荐

WordPress MultiSite(MU)子目录url/slug/permarink可以更改吗?

我目前正在与WordPress Multisite(MU)、BuddyPress和Commons in a Box(CBOX)合作,围绕一个中心用户群创建一个网站,该网站允许用户组成群组,并创建与其群组相关的“群组博客”。我在这个问题上发布了关于这个确切情况的进一步详细信息here.然而,我想问一个更一般的问题,关于WordPress多站点安装的性质,除了初始站点或网络主页。我的问题是,是否可以更改默认的子目录url结构/文件夹。例如,Multisite当前的默认设置为site。com/blog/sub-