Technology Blog »
June 17, 2007
[ Edited 8th June 2008: I'm not doing it this way any more. Read this more recent post for the lowdown. ]
It’s a frequently asked question – how do you get multiple blogs from a single installation of Wordpress? And the answer is surprisingly simple, if a little technical.
I wanted to use a blog for this site’s portfolio page. I already had WordPress installed, obviously, so I didn’t want to install a second copy and have to maintain it in parallel. That seemed stupid.
I read the WordPress page about multiple blogs and was inspired to make my own attempt. My solution, unlike similar ones linked from that page, does not involve symbolic links: my hosting does not permit them, and anyway I realised they aren’t actually necessary.
To start with I made a new directory “portfolio” and put a new index.php file in it. This index.php is like the standard WordPress one except that it loads the rest of the code from the “journal” directory instead of the local one. The change to do this involves only one line of code.
At this point you can run this PHP file and see it load the same blog as in the normal directory, which is rather useless but shows all is well.
WordPress needs to detect the directory it’s being invoked from and select its database settings accordingly: the code for this goes into config.php. I chose to set it up so that if it’s invoked from the “portfolio” directory a different table prefix is used.
Running the PHP file now from “portfolio” gives a different result: it is suggested that you run the install script to create the database tables for your new blog. But if you attempt to do so you’ll be disappointed as it returns a 404 not found error.
This is because only the index.php is present in the portfolio directory: all the other scripts such as the administration and installation ones are elsewhere. But this problem can be solved very easily on an Apache site: with a custom .htaccess file you can send all requests for any file except index.php to the “journal” directory instead.
Once that’s working the only remaining task is to theme your new blog. If you use a completely different theme to your existing one, there’s no problem, but if you want, as I did, to use the same theme with a few minor variations then you’ll need to insert tests for the request directory into your theme code.
(If anyone wants the code for this solution I’m happy to supply it — after I’ve tidied it up a little. Just let me know.)