Upgraded to WordPress 3.1.2

It’s been a little while since my last upgrade of WordPress for this blog, the last version is an old 2.2.2. WordPress has changed and improved a lot since then, so I decided to upgrade it to the latest version 3.1.2. Also, I also changed the theme to give it a new look. Hopefully this is a new chance for me to post more.

The migration was basically smooth, but I still got several small problems.

  • Post revision is a new feature comparing with older versions. But it will make the database bloated and sometimes it’s not really needed. It can be disabled by adding this line to wp-config.php just before the last line:
    define('WP_POST_REVISIONS', 0);

    The number defines the number of revisions will be kept in the database’s posts table, 0 is for disabled.

  • The structure of table wp_posts is changed. I backed up my old database then restored to the new installation, but I found there’s no trash link for me to retrieve or delete posts or pages I trashed. When I checked in phpMyAdmin, I found the post_status can not be set to trash. The trashed posts or pages are still in the database but you cannot delete them, this will cause some problems, e.g., I cannot generate a new post or page with the same slug that’s used by a trashed post or page. I solved this problem by backing up the old database by its data only without selecting the structure. So that the structure of the new database will not be changed.
  • In this new version, seems the problem for Chinese support is still there. As before, I need to change the following section in wp-config.php to make it display Chinese characters correctly:

    define('DB_CHARSET', 'utf8');


    define('DB_CHARSET', '');

WordPress database clean up

I tried to upgrade my blog to WordPress 2.5 days ago so I had the chance to check my MySQL database closely in PhpMyadmin. And I was astonished because the size of my database is over 4MB! That’s huge for a small scale blog. When I checked the tables in the database, I found there are two tables were uncommonly large: wp_comments and wp_options, both are over 1MB or more. When I checked them out by browsing their contents, I found that in the wp_comments table, there are tons of spam comments (marked “spam” in the “comment_approved” field). In the wp_options table, there are lots of unused options from uninstalled plugins left and there are lots of items begin with rss_. With a simple search on the net, I learned those spam comments and trackbacks are stored in the wp_comments table even though they are marked as spam and not posted to the blog. And for those options with rss_ prefix, they are RSS feeds contents used in WordPress dashboard, etc. So basically I don’t need them, especially when they make the database so fat and make the blog significantly slow.

To clean them, I just simply delete the spam comments and trackbacks in wp_comments table and rss_ items in wp_options table. The SQL query is like this:

DELETE FROM `wp_comments` WHERE `comment_approved` = 'spam'

After the clean up, my database is just about 900KB, what a difference! If you are not comfortable to edit in PhpMyadmin directly (like regedit in Windows), fortunately there are some plugins out there do the job well. CJD Spam Nuke and Clear Options are two of them and very easy to use. The latest Akismet plugin also can delete the spams from database manually or automatically.

WordPress and .htaccess problem

This is an old problem has existed for years, but I just encountered it days ago. In short, the symptom is that access to all password protected regular folders will be directed to the 404 page of WordPress, where “regular” means it’s not a WordPress page. I played around with both .htaccess files in my www root directory and in the protected directory, and found it should be caused by something within the Apache itself but I don’t know what exactly the reason is.

Finally I worked it out by asking on Site5′s forum and got the solution from this site. Because I installed WordPress in a sub-directory /blog under my root, so the solution is to modify the index.php file under the root folder from

< ?php
/* Short and sweet */
define('WP_USE_THEMES', true);


< ?php
/* fix password protected folder access */
$request_filename = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
$this_dir = dirname(__FILE__).'/';
if($request_filename!=$this_dir && $request_filename!=__FILE__ && (is_file($request_filename) || is_dir($request_filename))) {
  // we are not supposed be here!
/* Short and sweet */
define('WP_USE_THEMES', true);

After this modification, everything works well now.

Solution for video presentation in WordPress

I created a video collection page for my daughter’s blog long time ago but turned out to update it very slowly. A very important reason is the procedure to put the video online is much more complicated and time consuming than photo processing. Another reason is that the page lacks of convenient back end administration tools and playing controls. So I have been looking for a nice method to put video clips on blog for long time. What I want from this method is there’s a playing console so audience can watch the video clips without leaving the page. Another requirement is it must support playlist so that I can easily add or remove clips. Finally I found wordTube, a very nice WordPress plugin to integrate flash video player in WordPress, for various playlists or for single clip. Because of it, I spent some time these days to convert some of the old video files and find some other useful tools for this total solution. Following is my simple yet efficient solution to process video and put them online in WordPress.

  1. Capture
    I use a Panasonic PV-GS250 3CCD video camera for event video taping and a Fujifilm FinePix F30 for casual daily shooting. Both of them output good enough video quality for web presentation. The first step is to capture the video from the cameras to the computer. For F30, it’s just to download the AVI files to hard drive, and they have 640×480 resolution. For GS250, I use Ulead VideoStudio to capture from the tape and generally the file will be huge for a general length video clip, it also has 640×480 resolution. Now these downloaded or captured files are ready for editing.
  2. Edit
    This is the most time consuming step. I use Ulead VideoStudio for this task because of its intuitive interface and simplicity. Basically I just add titles and some simple transit effects between clips so more advanced softwares are just over kill. Besides titles and transit effects, I also do some cut and trim. So far I still leave the audio alone because for candid shooting of kids, I prefer to keep ambient sound. But I think I will try audio editing later. After all the edit, I export it to a video file. Currently I use Microsoft MPEG-4 Video Codec V2 because after some comparisons, I found it gives decent quality and relative small file size. So what I get is an AVI file with the original video size, 640×480.
  3. Convert
    In order to put the video online in a flash player, I need to convert the video files to flash video (FLV) format. There are many converting tool out of there, some are commercial and some are free. I tried some of them including Macromedia flash 8 Video Encoder, Riva FLV Encoder and SUPER. Finally I stay with Flash 8 Video Encoder because it gives high quality flash video with its On3 VP6 video codec. It has batch convert, it’s easy to use and it comes with Macromedia Flash 8. Riva FLV encoder is a freeware and very easy to use and the conversion is much faster than Flash 8 Video Encoder. But the quality is not so good as Flash 8 Video Encoder for similar or even greater data rate. I guess maybe that’s caused by its Sorenson Spark video codec though I am not clear about its technical details. The FLV Player comes with it is fine so I just keep it. I also tried SUPER, which is also free but I uninstalled it because it just doesn’t have any appealing advantages comparing with Flash 8 Video Encoder. In Flash 8 Video Encoder, I convert AVI files to 320×240 medium quality FLV files using On2 VP6 video codec, 96kbps stereo MPEG layer III (MP3) audio codec. The file size of the FLV file is only about 1/9 of the original AVI file. The FLV files can be played on local computer by an FLV player, or embedded into a flash player on the web.
  4. Flash player integration
    I use wordTube, a plugin for WordPress, to manage all the video (and audio) files and integrate them with the blog. It supports playlists so I can generate various playlists from the media center. Also, it’s very easy to embed a single video file in a blog post or page. This is a very convenient feature for podcast while one still wants to keep an archive of the whole media library in different categories (playlists). The plugin uses the JW Media Player to play media files. Options are provided to customize the player in the back end, including appearance and controls. The media files can be on your server, or can also be on any other remote servers as long as it can be accessed.
    UPDATED 2008-04-17: The latest version of JW Media Player now supports YouTube, means that you can embed YouTube videos in your OWN player without downloading the FLV files. It’s convenient to generate a list of all your videos hosted on YouTube.

Essentially this is my workflow for video manipulation. I think it’s efficient while with good quality for personal video showcase, such as for a kid’s blog. Please let me know if you have any other better ideas on this topic.

If you have your blogs hosted at BSP’s such as Blogger and WordPress.com, you are not able to install plugins so this method doesn’t apply to your case. An alternative is you can upload your video files to video hosting services such as YouTube or Google Video then embed the video in your posts or pages. Both YouTube and Google Video provide necessary code for this purpose. You can refer to the instruction here and here, respectively.

Other related resources

Two hacks about WordPress

  • To exclude page links in the navigation bar in the header.
    I have some pages that I want them to be accessible by the public but not listed in the navigation bar. After some search, I found this effective yet simple solution. What I did is to edit the header.php file in the current theme folder. Locate the function wp_list_pages and add exclude=pageID#,pageID# to its arguments, where pageID#s are the ID numbers of the pages to be hidden. Here is an example:

    <?php wp_list_pages('exclude=123&sort_column=menu_order&depth=1&title_li='); ?>

    where 123 is the ID of the page to be hidden.

    UPDATE: Just found a nice plugin, Page Link Manager, that does the same job in a much neater manner. Besides the option page, an “Include Page in Site Navigation” checkbox will be available when a page is being edited.

  • To exclude pages from the Extended Live Archive.
    I just installed this plugin to display the blog archives. It works very well in a very neat and intuitive way. But I found that it also includes pages by default and I couldn’t find the option to disable it. So I searched again and found a solution in their Flickr forum. What should be edited are two files in the plugin folder: af-extended-live-archive.php and af-extended-live-archive-include.php.
    In these two files, locate the following two expressions in both files

    post_status = 'publish'
    p.post_status = 'publish'

    then change them to

    post_status = 'publish' AND post_type='post'
    p.post_status = 'publish' AND p.post_type='post'

    respectively. That’s it. Now ELA displays posts only.

Feed aggregation in WordPress

During last weekend, I had an idea to aggregate the feeds from my daughter’s baby friends’ blogs and flickr photos into her blog so that we don’t have to visit them one by one. Though I can read the updates in Bloglines but it’s neat to put them together. After doing some search (salut Google!), I implemented this solution:

  1. Use Gregarius to aggregate all the feeds.
  2. Use rss2html free script to generate HTML code in a WordPress page.
  3. Use the phpexec plugin for WordPress to make PHP run inside a WordPress page possible.

Besides, I use cron job to make Gregarius update the feeds at a fixed time interval, say, every 2 hours.

This solution turns out to work very well. Gregarius is essentially a very good open source feeds aggregator and it can be used as a stand alone feeds reader on your own server. The free rss2html script just does what the name tells, and its simple template supported feature is very nice to format output style.

I also tried another WordPress plugin aggregated blog feeds and found it does similar things in a much simpler manner. But it strips all images in messages and I didn’t find an option to enable it. If only titles or abstracts are what you need for feed aggregation in WordPress, you gotta give it a try.

WordPress database backup and restore

I heard from a Chinese blog that it seems blogs hosted by weblogs.us were blocked by China’s “Great Fire Wall”. I am a little bit astonished because weblogs.us is not a large scale BSP at all. Anyway, it happens.

I ever considered to buy web hosting space and domain name to build my own homepage as well as blog. Now I have to consider it again, though the service offered by weblogs.us is unbeatable at this price ($0, thanks JD!). So I just tried to backup the database at weblogs.us and restore it on my local server as a rehearsal. It works well. With phpmyadmin, I can backup the whole database or any of the tables, then restore it by phpmyadmin on my local server. After restore, I need to browse the “options” table and modify the wordpress URI manually. Then I can access http://localhost/wordpress/wp-admin/. A theme needs to be selected if the theme used on weblogs.us is not installed on localhost yet, otherwise the blog will turns out to be empty. After that I have a mirror site of my blog on local.

Ref: Backing Up Your Database at WordPress.org Codex

Integrate Gallery and WordPress

I finally integrated Gallery with the Blix theme by taking the following link as a reference. It’s not a simple mission to do that, I really hope there will be such a plugin out soon.

Scattered » Gallery Integration with Kubrick and WordPress 1.2

Upgraded to WP

I just upgraded WordPress to its latest version following this guide. It’s pretty easy and very smooth if you have backuped all the files you have modified, e.g., themes, plugins and files in the wp-admin folder. So far it’s working well and I have not found any changes yet, except the green bars on the activated theme and plugins. :) Hope everything is fine.

Import from blogware .xml file to WP

UPDATE: I tried it and it works just fine. But need to modify a little to make the GMT offset works.
Details here: http://mosquito.wordpress.org/view.php?id=878

When importing an rss2 feed I discovered all posts dats were set to GMT time and the offset seemed to be ignored. Found that the values were simply being switched. Made the following changed to lined 148-149 in import-rss.php

148: switch variables
DATE_ADD(‘$post_date’, INTERVAL ‘$add_hours:$add_minutes’ HOUR_MINUTE)

149: replace
DATE_ADD(‘$post_date’, INTERVAL ‘$add_hours:$add_minutes’ HOUR_MINUTE)

Quoted from http://wordpress.org/support/topic.php?id=28115.

I just got it to work. There seems to be two problems:

1. The import-rss.php file is looking for a or type of tag.

2. The excerpts that Blogware exports seems to be problematic. The import-rss.php file *seems* to read in the title, date, etc that it wants and then assumes the rest is the actual entry. Not true in Blogware’s case – the excerpt comes before the body.

To solve problem 1:

In the import-rss.php file, find the line that says:

preg_match_all(‘|(.*?)|is’, $importdata, $posts);
and change it to:
preg_match_all(‘|(.*?)|is’, $importdata, $posts);

To solve problem 2:

Find the line that says:
preg_match(‘|(.*?)|is’, $post, $content);
and change to to read:
preg_match(‘|(.*?)|is’, $post, $content);

I also changed the line that said:

preg_match(‘| (.*?)|is’, $post, $date);
preg_match(‘| (.*?)|is’, $post, $date);

But I’m not sure that was required.

With respect to point number 1: This will only import your articles. If you have photos, reviews, whatever else, then you will have to manually change the to and then run it again. Then change it to and run it again..and so on until all your different post types are imported.

There is syntax to tell preg_match() to look for