Importing Haloscan comments into WordPress from Blogger

Update, please read this first!
The instructions below only worked for WordPress 1.5, 2.0, 2.1, and 2.2 before Google released a new version of Blogger—which broke the WordPress importer. Since that time, these instructions have ceased to be useful. However, if you’ve recently imported your Blogger blog into WordPress 2.3 (or are planning to) and need to import your Haloscan comments, check out my new post created specifically for you: Importing Haloscan comments into WordPress 2.3 from Blogger. I’m leaving this post here for posterity, but since it’s no longer doing anybody any good, I’ve closed the comments.

Background

WordPress logoJudging by the response to my original moving from blogger to wordpress post, this is a popular topic. However, I only meant for that post to be useful to the next hacker down the line and not so much for the faint of heart. This post seeks to remedy that oversight with an improved script for importing Haloscan comments into WordPress.

This was made possible after Haloscan fixed their comment export feature so that html is no longer stripped from the comment text. The other night I looked back at some code I had pieced together based on Phil Ringnalda’s code from his post, Importing YACCS comments in Movable Type, and I was able to finish the Haloscan importer the way I had originally intended: without screen scraping! If you have any problems or suggestions, feel free to leave a comment. Enjoy.

Step 1: Upgrade Haloscan

Only “premium” customers have access to Haloscan’s export comments feature. Bah! The only way to get around this limitation and get access to your comments for export is by donating $12 to Haloscan. If you do make the donation, the instructions and code below (for versions 1.5.x and 2.x of WordPress) should work for you.

Step 2: Import Blogger posts into WordPress 2.x

If you’ve already imported your Blogger posts using WordPress 2’s importer without the modification below, you will need to delete the posts you’ve imported, make the modification described in step 2, and rerun the importer. Luckily I’ve created a plugin to make deleting all of your blog posts a snap.

  1. Open /path/to/wordpress/wp-admin/import/blogger.php in a text editor
  2. Find the following line (line 404 in v2.0.2)
    $post_content = $postinfo[2];

    and change it to this:

    $post_content = "<!--" . $postinfo[3] . "-->" . $postinfo[2];

    Explanation: This stores each blogger post id as an html comment at the beginning of the post, which is used later to associate the post with the appropriate Haloscan comments.

  3. Save the file and then return to a web broswer
  4. Log in to the WordPress administrative interface and select the “Import” option from the top menu, and then select “Blogger” and follow the instuctions for importing your posts
  5. Continue with Step 3: Importing your Haloscan comments below

Update: If you’re interested in maintaining the permalinks to your posts, I’ve written a post called Maintain permalinks moving from Blogger to WordPress that requires three additional changes to the blogger.php script, which need to be made before you run the import. (17-Oct-2006)

Step 2B: Import Blogger posts into WordPress 1.5.x

Note: This step is left here for historical purposes. WordPress 2 comes with a significantly more advanced importer for Blogger which should be used instead of the instructions below. If you’re importing into WordPress 2.x, skip to Step 3.

The instructions marked with an asterisk (*) below are slightly different from the instructions that come with the import-blogger.php script provided by WordPress. In particular, step 7 is crucial in order to import comments from Haloscan.

If you’ve already imported your Blogger posts into WordPress using the provided import-blogger.php script and you can’t or don’t want to delete the posts that you’ve already imported, I’ve written a script to insert the Blogger post IDs into your WordPress posts so that you’ll be able to successfully import your Haloscan comments.

Just download insert-blogger-post-ids.zip, unzip it, and upload insert-blogger-post-ids.php to your wp-admin directory. Then run it in your browser like you did import-blogger.php. Now you can skip down to the section entitled “Importing your Haloscan comments”.

  1. log in to Blogger
  2. go to Settings > Publishing and set FTP Path to your WordPress install e. g. /path/to/wordpress/
  3. *change Blog Filename to wordpress.html
    explanation: prevents creating an index.html file in wordpress directory—this file can be deleted later
  4. go to Settings > Formatting and change Timestamp Format to mm/dd/yyy hh:mm:ss tt (the first option) and set Enable float alignment to “No”
    explanation: the second change prevents Blogger from inserting unnecessary formatting markup at the beginning and end of each post
  5. go to Settings > Archiving and set Archive Frequency to “Monthly”, set Archive File name to wordpress.php, and set Archive Path to your WordPress install e. g. /path/to/wordpress/ (should be the same as above)
  6. *set Enable Post Pages to “No”
    explanation: prevents creating post pages filed under directories named 2004, 2005, etc in your WordPress directory which would eventually collide with permalink rewrites
  7. *go to Template > Edit Current and replace your template with the following line of code
    <Blogger><wordpresspost><$BlogItemDateTime$>|||<$BlogItemAuthorNickname$>|||<!--<$BlogItemNumber$>--><$BlogItemBody$>|||<$BlogItemNumber$>|||<$BlogItemSubject$></Blogger>

    explanation: includes the unique blogger post id within an HTML comment in the body of each post

  8. Click “Save Template Changes” and then click “Republish” to republish your blog
  9. goto http://example.com/wordpress/wp-admin/import-blogger.php where example.com/wordpress is replaced with the domain name and path to your WordPress install
  10. click OK at the bottom of the page to import your Blogger posts

Step 3: Importing your Haloscan comments

import-haloscan.php has be revised for WordPress 2.x so that comment counts are now automatically incremented.

  1. Download and unzip import-haloscan-2.0.zip (v2.0)
  2. Upload import-haloscan.php to your wp-admin directory
    /path/to/wordpress/wp-admin/
  3. log in to Haloscan
  4. go to Manage Comments > Export
    Note: only “premium members” have access to export their comments, but if you’re really serious about leaving Haloscan, you might be willing to donate the $12 necessary to gain access to your comments for exporting.
  5. There will be an export link for every thousand comments you have. Clicking one of the export links will prompt you to save the file as “export.xml”. If there is more than one link (i.e. if you have more than 1000 comments), rename the first file to export1.xml, the second file to export2.xml, and so on. Save the files to your desktop and upload them to your WordPress directory
    /path/to/wordpress/
  6. Go to http://example.com/wordpress/wp-admin/import-haloscan.php where example.com/wordpress is replaced with the domain name and path to your WordPress install
  7. Click OK at the bottom of the page to import your Haloscan comments

Feel free to if you found this useful.