存档

文章标签 ‘wp’

drupal向wp的移植过程

2008年5月24日 robertbao 3 条评论

终于下了决心把drupal整个换为wp了。

1、wp的表结构比drupal简单很多,要移植的主要就是四张表,

分类表wp_categories:

insert into wp_categories (cat_id, cat_name, category_nicename, category_description, category_parent) select term_data.tid, name, name, description, parent from term_data, term_hierarchy where term_data.tid=term_hierarchy.tid;

update wp_categories set category_count = (select count(post_id) from wp_post2cat where wp_categories.cat_id = wp_post2cat.category_id);

文章表wp_posts:

insert into wp_posts (id, post_date, post_content, post_title, post_excerpt, post_name, post_modified) select distinct n.nid, from_unixtime(created), body, n.title, teaser, replace(replace(replace(replace(lower(n.title),' ', '_'),'.', '_'),',', '_'),'+', '_'), from_unixtime(changed) from node n, node_revisions r where n.vid = r.vid;

update wp_posts set post_name = replace(post_name, '_', '-');

文章分类关系表wp_post2cat:

insert into wp_post2cat (post_id,category_id) select nid,tid
from term_node ;

评论表wp_comments:

insert into wp_comments(comment_post_id, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url) select nid, from_unixtime(timestamp), comment, thread, name, mail, homepage from comments ;

update wp_posts set comment_count = (select count(comment_post_id) from wp_comments where wp_posts.id = wp_comments.comment_post_id);

2、移植过程中一些问题的修正,

分类表中文章数:

update wp_categories set category_count =84 where cat_id=1;
update wp_categories set category_count =205 where cat_id=5;
update wp_categories set category_count =142 where cat_id=6;
update wp_categories set category_count =274 where cat_id=11;

参数表:

update wp_options set option_value='http://www.robertbao.com' where option_id=40 or option_id=1;

3、三个post转为page,并将post调整从1149开始继续计数,

alter table wp_posts auto_increment = 1149;

delete from wp_post_counter_time where post_id>='9527';
delete from wp_post_counter where post_id>='9527';
delete from wp_postmeta where post_id>='9527';

delete from wp_posts where id='1';
delete from wp_posts where id='2';
delete from wp_posts where id='3';

update wp_posts set id='1',guid ='http://www.robertbao.com/?page_id=1' where id='1151';
update wp_posts set id='2',guid ='http://www.robertbao.com/?page_id=2' where id='1150';
update wp_posts set id='3',guid ='http://www.robertbao.com/?page_id=3' where id='1149';

分类: WORK 标签: , ,

从 MT 迁移到 WP 后的网页链接问题

2005年12月4日 robertbao 没有评论

Movable Type和WordPress是两个现在非常流行的Blog系统,两者都是非常棒的Blog系统,都能够支持单用户和多用户,功能也都很强大,插件和皮肤也是应有尽有。它们采用的机制有些区别,很难说谁更好…

因为WordPress安装使用更方便一些,有不少人现在从Movable Type转迁移到WordPress,这里只是对转移后的链接问题做一些探讨:

由于以前用Movable Type写的blog已经被Google等搜索引擎索引了,如果现在blog的链接地址改变的话,原来被索引的链接就会变成死链,也就是说别人点击这个链接并不会看到他希望的内容,这对网站的访问量会有很大的影响,所以我们需要改造WordPress下blog的链接地址。

方法是:将WordPresss的URL使用Movable Type的Permalink结构,即从外部看两者具有相同的Url。在WordPresss中将Permalinks设置为/archives/%year%/%monthnum%/%postname%.html,这里还有一个小问题,因为%postname%在WordPresss中,是使用”-”号来代替空格,而Movable Type使用的是”_”号,因此,需要在WordPresss上安装一个叫”Underscore Permalinks Plugin”的插件。

这个插件很简单,只是一个PHP文件。先建立一个文件,命名为underscorepermalinks.php,内容如下:

/*
Plugin Name: Underscore Permalinks
Plugin URI: http://wordpress.org/#.
Description: Converts spaces to underscores when sanitizing post titles for use in permalinks. This is handy for those moving from Movable Type who want to maintain their old permalink style.
Version: 1.0.1
Author: Ryan Boren
Author URI: http://boren.nu/
*/
function sanitize_title_with_underscores($title) {
$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = preg_replace('/[^a-z0-9 _-]/', '', $title);
$title = preg_replace('/\s+/', ' ', $title);
$title = str_replace(' ', '_', $title);
$title = preg_replace('|_+|', '_', $title); return $title;
}
remove_action('sanitize_title', 'sanitize_title_with_dashes');
add_action('sanitize_title', 'sanitize_title_with_underscores');
?>

然后复制到plugins目录下的Activate。

这样原来Movable Type中的blog导入后,在WordPresss中的URL将和原来的完全一样,就实现了链接的平滑迁移。

当然你搭建WordPresss的主机需要有Url Rewrite的支持才能使用以上的方法。

分类: WORK 标签: ,