我最近为一个客户端需要这个(他也想这么做,但可以自己在wordpress后端创建一个存档),但找不到一个好的插件。实际上,定制代码很容易。你只需要make your install a network install 然后放置一个自定义install.php
在您的wp-content
要覆盖的文件夹wp_install_defaults() 作用在这个函数中,您只需编写几个SQL语句,将内容从一个站点移动到另一个站点。
最后,我唯一需要做的就是创建这个自定义install.php
(您可能需要修改此选项以满足您的需要,但我想这是一个很好的起点):
<?php
function wp_install_defaults($user_id) {
global $wpdb, $table_prefix;
// we\'ll truncate the options table later on, these are the options we want to keep, therefor we fetch them here.
$options = array(\'siteurl\', \'blogname\', \'blog_description\', \'home\');
$options = dlx_archive::getOptions($options, $table_prefix);
$wpdb->query("TRUNCATE {$table_prefix}options");
// also alter the term table (plugin install will hook later, but we can\'t transfer now if the table scheme isn\'t synced).
$wpdb->query("ALTER TABLE {$table_prefix}terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT \'0\'");
$tables = array(
\'terms\',
\'term_taxonomy\',
\'term_relationships\',
\'posts\',
\'postmeta\',
\'avhec_category_groups\',
\'options\'
);
// this will sync the data between main blog and archive.
dlx_archive::copyData($tables, $wpdb->base_prefix , $table_prefix);
// write the options back to the table.
dlx_archive::writeOptions($options, $table_prefix);
// delete all posts from the main blog (explude epaper category (term 18)
$wpdb->query("DELETE {$wpdb->base_prefix}posts FROM {$wpdb->base_prefix}posts
LEFT JOIN {$wpdb->base_prefix}term_relationships wptr ON wptr.`object_id` = {$wpdb->base_prefix}posts.`ID`
WHERE {$wpdb->base_prefix}posts.post_type = \'post\'
AND wptr.term_taxonomy_id != 18");
// we just imported new permalinks settings to the wp_options table, flush the rewrite rules now.
flush_rewrite_rules();
}
class dlx_archive {
static function copyData(array $tables, $source_prefix, $target_prefix) {
global $wpdb;
foreach($tables as $table) {
$sql = "INSERT " . $target_prefix . $table . " SELECT * FROM " . $source_prefix . $table;
$wpdb->query($sql);
}
}
static function getOptions($array, $table_prefix) {
foreach($array as $option) {
$options[$option] = self::getOptionValueFromDB($option, $table_prefix);
}
return $options;
}
static function getOptionValueFromDB($key, $table_prefix) {
global $wpdb;
$option = $wpdb->get_row("SELECT * FROM {$table_prefix}options WHERE option_name = \'{$key}\'");
return $option->option_value;
}
static function writeOptions($options, $table_prefix) {
global $wpdb;
foreach($options as $key => $val) {
$sql = "UPDATE {$table_prefix}options SET option_value = \'{$val}\' WHERE option_name = \'{$key}\'";
$wpdb->query($sql);
}
}
}
如果安装了大量插件,还需要单独关注自定义表。我只安装了一个插件(需要修改
avhec_term_order
) 只有
基本上,如果你在网络管理中创建一个新站点,那么它会将所有帖子从你的主博客移动到你的存档博客中。
性能方面的MySQL不能很好地处理大型表,使用完全独立的数据库对性能没有好处。根据我的经验,使用单独的表格就足够了。但是,如果您出于某种原因真的想拥有独立的数据库(上述解决方案仅基于表,因为这是WPMU的工作方式),您可以看看HyperDB.