Wordpress Blogger Import

July 25th, 2005  |  Published in Out Loud  |  5 Comments

For those interested in importing Blogger posts into Wordpress and maintaining your old permalink structure for single post pages, here’s what I did.

The problem: Blogger creates permalinks using the post title differently than Wordpress. For one thing, Blogger doesn’t require a post title, and will build permalink using the first few words of the post content. Now, WP doesn’t really need a title either, but you certainly have to have a post_name or you’ll get an unusable permalink and won’t be able to access the post.

Rather than trying to guess Blogger’s method, I decided to modify the import-blogger.php script (NOTE: i’m using the already modded Skelton script to bring in both posts and comments. The code will be different if you’re not using this version of the script.)

I’m not going to pretend this is very good code. I was tired and kinda pissed that WP wasn’t already importing the Blogger permalinks, since if you’re transferring an old site to WP, then you obviously want old links to work (easily accomplished with some simple rewrite rules IF AND ONLY IF you have the correct post_name/slug).

So here we go.

The Skelton Import-Blogger Script is here:
http://catsutorials.catsudon.org/?p=15

NOTE: The blogger permalinks I had to import were of the form “http://www.example.com/2004/03/post-title.html”.

First, I added a Blogger tag (< $BlogItemPermalinkURL$>) to the import template at the end of the post part, before the comment part. Example follows:

< $BlogItemDateTime$>|||< $BlogItemAuthorNickname$>|||< $BlogItemBody$>|||< $BlogItemNumber$>|||< $BlogItemSubject$>|||< $BlogItemPermalinkURL$>< $BlogCommentDateTime$>|||< $BlogCommentAuthor$>|||< $BlogCommentBody$>

Then, I added the following after line 66 (”$post_title = $postinfo[4];“):


$tb_permalink = $postinfo[5];
$post_name = strrchr($tb_permalink, “/”);
$post_name = str_replace(”/”,”",$post_name);
$post_name = str_replace(”.html”,”",$post_name);

These lines get the permalink from the array, grab the filename and remove the file extension. Now, this is what we want to import into WP. No guessing required. :>

Around line 150 of the import-blogger.php script I add this:


$result = $wpdb->query("
INSERT INTO $wpdb->posts
(post_author,post_date,post_content,post_title,post_category,post_name)
VALUES
('$post_author_ID','$post_date','$post_content','$post_title','2','$post_name')
");

All I’ve done here is add the post_name field and value to the query. Very simple.

What else? Nothing. Upload the script, run it as usual, but now you’ll see that you have the Blogger-style post_names for your permalinks. What did I use for my rewrite rules?


RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)\.html$ $1/$2/$3/ [QSA,R]

I put this code outside of the Wordpress rewrite rule block in the .htaccess file, since I didn’t want WP messing with it. You’ll want to change your RewriteBase appropriately. It should probably be the same as whatever your Wordpress ReWriteBase is.

This may only be for my benefit, but hey, why not archive it online? I mean, that’s the first place I look anyway.

THE END.

Responses

  1. Bogle’s Blog » Migrating from Blogger to Wordpress says:

    September 7th, 2005 at 4:58 pm (#)

    [...] till doesn’t ensure that permlinks to your site still work. Fortunately, < a href=”http://thinkcorps.com/2005/07/25/wordpress-blogger-import”>Thinkcorps has written an additional patch that preserves permlinks. To save you [...]

  2. Jim Mckeeth says:

    November 14th, 2005 at 11:03 pm (#)

    I tried the changes you specifed and got mixed results. Some of the permalinks were close. They had the extensions, but also still had a trailing backslash. Als the rewrite seemed to cause other problems on the blog. Any additional tips would be great! Maybe even if you could share your actual script. . .

  3. BaseBlogging » Leaving Blogger - How says:

    December 26th, 2005 at 8:45 pm (#)

    [...] ore talented than myself took the initiative to fix both the former and the latter. The first step I took was to setup a subdomain to install Wordp [...]

  4. رضا says:

    July 14th, 2007 at 6:01 am (#)

    great for transfering from blogger to wordpress

    رضا

  5. TJantunen says:

    October 8th, 2008 at 10:19 am (#)

    Hi,
    I wrote these http://tjantunen.com/2007/03/21/import-blogger-posts-to-wordpress/
    simple instructions how to import blogger beta posts to wordpress easily and without using any plugins.

Leave a Response