I host a blog for a friend of mine who is teaching herself CSS and HTML so she can customize her WordPress instance.
As she is new at this and because it’s just bad form to make changes to your production environment, I want to set up a dev instance of WordPress for her, complete with all the content she has already created. The problem with this is that the theme of a WordPress instance is set in the database, so it’s not as simple as just having your second installation pointing to the same tables as your first, because changing the theme of the first also changes the theme of the second.
This will walk you through the steps you need to take to have a second WordPress instance use the same content as the first, but be able to set a different theme.
First things first, create a sub-directory in your www-root directory, I’m calling mine dev:
user@host:~$ mkdir sitename.com/dev/
Then copy the contents of your first WordPress instance into the subdirectory:
user@host:~$ rsync -r ~/sitename.com/ ~/sitename.com/dev/
Now we have two identical WordPress instances displaying the same content, fed from the same database, at two different URLs:
http://www.sitename.com and http://www.sitename.com/dev/
However, any links you click on the dev/ instance will take you back to the root instance, so we have to add these two lines to the dev copy of wp-config.php:
define('WP_HOME', 'http://www.sitename.com/dev');
define('WP_SITEURL', 'http://www.sitename.com/dev');
On to the database itself. There are two values that dictate the current theme of your blog, both are found in the wp_options table. These values are template and stylesheet. Using phpMyAdmin run this query against your WordPress db to find the fields in question:
SELECT * FROM wp_options WHERE option_name = 'template' OR option_name = 'stylesheet'
Duplicate both of the fields with a new option_name, I used temple_dev and stylesheet_dev, and give them a value to begin with, twentyeleven in our case.
The next step is to actually have our PHP files reference our newly created development template definitions. To do this we make the following replacements in the below files, I’ve included the line numbers to make life a little easier. Everywhere you see either template_dev or stylesheet_dev they have replaced template and stylesheet, respectively.
~/sitename.com/dev/wp-admin/custom-background.php:381: update_post_meta( $id, '_wp_attachment_is_custom_background', get_option('stylesheet_dev' ) );
~/sitename.com/dev/wp-admin/custom-background.php:418: update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet_dev' ) );
~/sitename.com/dev/wp-admin/includes/template.php:1462: $stylesheet = get_option('stylesheet_dev');
~/sitename.com/dev/wp-admin/includes/upgrade.php:343: $template = __get_option('template_dev');
~/sitename.com/dev/wp-admin/includes/upgrade.php:1885: $current_template = __get_option('template_dev');
~/sitename.com/dev/wp-admin/includes/upgrade.php:1887: update_option('template_dev', $template);
~/sitename.com/dev/wp-admin/includes/upgrade.php:1888: update_option('stylesheet_dev', $template);
~/sitename.com/dev/wp-includes/theme.php:147: return apply_filters('stylesheet_dev', get_option('stylesheet_dev'));
~/sitename.com/dev/wp-includes/theme.php:240: return apply_filters('template_dev', get_option('template_dev'));
~/sitename.com/dev/wp-includes/theme.php:517: if ( get_option('stylesheet_dev') == $stylesheet_or_template )
~/sitename.com/dev/wp-includes/theme.php:519: elseif ( get_option('template_dev') == $stylesheet_or_template )
~/sitename.com/dev/wp-includes/theme.php:679: update_option( 'template_dev', $template );
~/sitename.com/dev/wp-includes/theme.php:680: update_option( 'stylesheet_dev', $stylesheet );
~/sitename.com/dev/wp-includes/theme.php:1003: $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet_dev'), 'orderby' => 'none', 'nopaging' => true ) );
