As you could read in my previous post, I converted my weblog from Nucleus CMS to Wordpress. This article illustrates how I did it.
I started by looking for a converter for Nucleus to Wordpress. I was happy to find one for Wordpress 2.1. Because I wanted to do most of the work while being offline (on the train), I then setup a local environment. This was very easy with XAMPP. After having the Magic LAMP running, I created a local database and imported all my Nucleus tables. Then I installed Wordpress 2.1 in my local environment and started the conversion. It must have been my lucky day, everything seemed to work and my Nucleus content (items, comments, users, trackbacks etc) were imported into Wordpress. After the import i could easily update Wordpress 2.1 to 2.7.
The next important step: convert my carefully crafted (
) Nucleus skin to a Wordpress theme. I thought this would be rather time consuming, but actually it only took me 10 hours (on the train) to completely convert my skin. I started from the default Wordpress theme, which was very helpful to see how everything works. Other details in this step are less important, because they are specific to my theme.
Because I get quite a few incoming links from Google and other sites, I wanted to keep the Nucleus FancyURL’s working and redirect visitors of the ‘old’ urls to the new ones. To get this working I took a few steps. A FancyURL in Nucleus looks like http://budts.be/weblog/item/123. However a url in wordpress looks like http://budts.be/weblog/2009/01/my-post. So first I had to find the mapping between the old Nucleus ID’s every item and it’s new Wordpress permalink. To do so I used a hackish SQL query on the database:
select CONCAT('$items[',n.inumber,'] = "',year(w.post_date),'/', month(w.post_date),'/',w.post_name,'/";') from wp_posts w, nucleus_item n where n.ibody = w.post_content |
The query missed a few items, but i guess a 90% ratio is good enough (the earth won’t end if a few items aren’t correctly mapped, right?). This query gives output such as:
$items[549] = "2005/10/het-wordt-weeral-herfst/"; $items[550] = "2005/11/digg/"; $items[551] = "2005/11/how-to-tuesday-disable-autorun-on-windows/"; |
This is the code that I copy pasted in a new PHP-file with the name ‘redirector.php’. This PHP-script looks like:
<?php if ($_GET["type"] == "category") { redirectCategory(intval($_GET["id"])); } if ($_GET["type"] == "item") { redirectItem(intval($_GET["id"])); } print "euhr.. hmm yeah.. this doesn't look very good."; function redirectCategory($categoryID) { $categories = array(); $categories[1] = "general/"; $categories[2] = "eten/noodles/"; ... $categories[24] = "muziek/"; if (array_key_exists($categoryID, $categories)) { header('Location: /weblog/category/'.$categories[$categoryID]); } else { header('Location: /weblog/'); } } function redirectItem($itemID) { $items = array(); $items[26] = "2003/09/pingtest/"; $items[27] = "2003/09/dit-is-cht-gestoord-maar-wel-grappig/"; $items[28] = "2003/09/nog-meer-noodles/"; ... $items[583] = "2008/04/antwerp-10-miles/"; $items[585] = "2008/05/een-huis-kopen-t-is-niet-gelijk-naar-den-bakker-gaan/"; if (array_key_exists($itemID, $items)) { header('Location: /weblog/'.$items[$itemID]); } else { header('Location: /weblog/'); } } ?> |
Still one thing about the SQL query: it produces dates such as 2009/2/foo-bar, while it should be 2009/02/foo-bar (although both seem to work in Wordpress). So before pasting the output of the query in the redirector.php script I first did a find/replace (with regular expressions) on the output with jEdit, by searching for "200([0-9])/([0-9])/ and replacing it with "200$1/0$2/. For the category mapping (also in the redirector.php-script) i used a similar query.
The next step is some .htaccess-magic. So before the first default Wordpress RewriteCond I added the following rules:
# cool uri's never expire (old nucleus blog url's)
# fancy urls
RewriteRule blog/[0-9]+/item/([0-9]+).*$ redirector.php?type=item&id=$1 [R,L]
RewriteRule blog/.*$ /weblog/ [R,L]
RewriteRule member/.*$ /weblog/ [R,L]
RewriteRule archive(/[0-9])?/([0-9]{4})-([0-9][0-9]).*$ /weblog/$2/$3/ [R,L]
RewriteRule item/([0-9]+).*$ redirector.php?type=item&id=$1 [R,L]
RewriteRule category/([0-9]+)(/.*)?$ redirector.php?type=category&id=$1 [R,L]
# feeds
RewriteRule atom\.php /weblog/feed/atom/ [R,L]
RewriteRule xml-rss.?\.php /weblog/feed/ [R,L]
RewriteRule xml-rss-comments\.php /weblog/comments/feed/ [R,L] |
These rules try to rewrite as much as possible, sometimes by redirecting to the redirector.php script to find the correct mapping. If a good redirect can not be done or found (in case of a mapping), the visitor is redirected to the home-page.
I guess that describes the steps I took to convert my blog from Nucleus to Wordpress. Now it is plugin-playing and -discovering time
.
Posted on Tuesday, January 13th, 2009 at 21:10 in Weblog.
Tagged with: convert en howto nucleus wordpress
This blog is powered by WordPress and is hosted by Dreamhost
Get Mozilla Firefox and rediscover the web.
Comments
There are currently 2 comments on this post. You can follow any responses to this entry through the feed.
krzychu wrote:
Your tips about importing/migration from Nuclues to WP works very well. Thank you!
One question left about your redirector hack: is it working even if nucleus files and database is missing?
teranex wrote:
@krzychu yes it works without the Nucleus files and database, because it uses mod_rewrite (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html). Please note that you will have to modify it fit your needs. Have fun with your converted blog
Add a Comment
Both comments and pings are currently closed.