Thesis Hive: Multiple Thesis Sites, One Set of Files
I have two regular blogs running Thesis and one development blog also running Thesis. Each blog has about a dozen
Tweet ThisWritten by Damon on April 1, 2009
I have two regular blogs running Thesis and one development blog also running Thesis. Each blog has about a dozen plugins in common.
Updating WordPress, the plugins, and Thesis is a pain as it is, so you can imagine how I feel about updating everything three times.
For WordPress and the plugins the solution is WP Hive which lets you use one set of source files for multiple sites. Each site gets its own settings and themes. Each site gets its own set of .htaccess and robots.txt files.
WP-Hive doesn’t let you create your own set of Thesis customizations for each set. The problem is that Thesis isn’t a theme so much as a framework and, if you like using the Thesis framework, then you’re probably going to want to use it for all of your sites each with its own set of customizations.
You can get around this by uploading Thesis multiple times renaming the Thesis theme folder each time. But if you’re lazy like me you’re not going to like updating each Thesis installation every time a new release comes out. Luckily there is a much more simple and elegant solution that makes updating and maintaining your blogs easily.
Add this code to your custom_functions.php file in your WP Hive enabled WordPress installation.
function thesis_hive() {
// Get the correct host name
$hostname = $_SERVER['X_FORWARDED_HOST'] == false ? $_SERVER['HTTP_HOST'] : $_SERVER['X_FORWARDED_HOST'];
// Strip any leading or training dots
$hostname = strtolower(trim($hostname, "."));
// Strip the www prefix
if (substr($hostname, 0, 4) == "www.") {
$hostname = substr($hostname,4);
}
//custom css
if ( ! file_exists(THESIS_CUSTOM . '/' . $hostname . '_custom.css') ) {
fopen(THESIS_CUSTOM . '/' . $hostname. '_custom.css','w+');
}
echo '';
//custom_functions.php
if ( ! file_exists(THESIS_CUSTOM . '/' . $hostname . '_custom_functions.php') ) {
fopen(THESIS_CUSTOM . '/' . $hostname . '_custom_functions.php','w+');
}
if (file_exists(THESIS_CUSTOM . '/'.$hostname.'_custom_functions.php')){
include(THESIS_CUSTOM . '/'.$hostname.'_custom_functions.php');
}
}
add_action('wp_head','thesis_hive');
This will code will automatically create a new set of custom.css and custom_functions.php file for each site the first time someone visits the site after adding the code and link or include the files.
Your custom folder will look like this:
cache/
custom_functions.php
custom.css
hostname1.com_custom_functions.php
hostname1.com_custom.css
subdomain.hostname1.com_custom_functions.php
subdomain.hostname1.com_custom.css
hostname2_custom_functions.php
hostname2_custom.css
etc…
Use the main custom_functions.php file for functions you want to use in all of your sites and the hostname_custom_functions.php file for functions that are specific to that one site.
The various custom.css files can be used the same way.
Final Notes
One drawback of this approach is that calling the functions within Thesis limits the scope. I don’t think you’ll be able to use WordPress functions and WordPress hooks in the hostname_custom_functions.php files. This hasn’t been a problem for me, but you should be aware of it when implementing a Thesis hive.
Thanks to Alex Tran in the comments who mentions a thread in the Thesis forums about creating multiple Thesis image rotators with WP Hive. My Thesis hive script doesn’t allow for multiple image rotators so, if that’s important to you, then go check it out.
Finally, if you have multiple Thesis sites, then you really should have a Thesis Developers License.