你可以把它放在一個插件,你只需上傳,激活和刪除。 這是我使用,修改爲您的使用(還沒有測試它):
<?php
/*
Plugin Name: Startup Settings
Plugin URI: http://someurl/
Description: Some description
Version: 1
Author: Your Name
Author URI: http://yoursite.com
*/
function startup_settings()
{
// Remove "Hello world" post and comment.
wp_delete_post(1, TRUE);
wp_delete_comment(1);
// Insert your pages.
global $user_ID;
$about_page = array(
'post_title' => 'About us',
'post_content' => 'Your content goes here',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'page',
'post_category' => array(0)
);
$post_id = wp_insert_post($about_page);
$contact_page = array(
'post_title' => 'Contact us',
'post_content' => 'Your content goes here',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'page',
'post_category' => array(0)
);
$post_id = wp_insert_post($contact_page);
// if you want to load the privacy text from a external file (untested)
$myFile = "/path/to/privacy.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$privacy_page = array(
'post_title' => 'Privacy',
'post_content' => $theData,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'page',
'post_category' => array(0)
);
$post_id = wp_insert_post($privacy_page);
// Set some deafault options if you want.
$options = array(
'comment_max_links' => 0,
'comments_per_page' => 0,
'date_format' => 'd.m.Y',
'default_ping_status' => 'closed',
'links_updated_date_format' => 'l, F j, Y',
'permalink_structure' => '/%postname%/',
'rss_language' => 'en',
'use_smilies' => 0
);
foreach ($options as $option => $value)
{
update_option($option, $value);
}
return;
}
register_activation_hook(__FILE__, 'startup_settings');
?>
Boldewyn,似乎wp_insert_posts()可能是要走的路,但我只是不知道如何在插入多個崗位同一時間。這是異步嗎? – 2010-02-10 15:44:03
我想,您必須多次爲每個要插入的頁面調用它。 「異步」是什麼意思? – Boldewyn 2010-02-10 16:41:00
這也是我想學習的東西:插入多個頁面,可能使用php循環?而且它也必須可以插入自定義字段? – markratledge 2010-02-10 17:19:34