Two Wordpress blogs, one site
Sunday, June 17th, 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.)








July 2nd, 2007 at 4:11 am
Hi there,
I would like to know the code snippets you used for this, I’m not worried if it’s untidy.
Thanks for your help,
July 2nd, 2007 at 9:33 am
OK, Ant, here goes:
In the home directory for my new blog, I created an index.php like this, pointing to my existing blog directory:
<? define('WP_USE_THEMES', true); require_once('../journal/wp-blog-header.php');In the same directory I created a .htaccess to route other requests to the existing blog:
RewriteEngine On RewriteCond %{REQUEST_URI} ^/portfolio$ RewriteRule . /portfolio/ [L,R=301] RewriteCond %{REQUEST_URI} !^/portfolio/$ RewriteCond %{REQUEST_URI} !^/portfolio/index.php$ RewriteRule ^(.+) /journal/$1Then I edited wp-config.php so it specified a different table prefix for my new blog, changing the assignment of $table_prefix to this:
if(substr($_SERVER['REQUEST_URI'], 0, 10) == '/portfolio') { $table_prefix = 'pf_'; } else { $table_prefix = 'wp_'; }At that point I requested the new blog and got the installation dialog. After following it my new blog was basically ready, except for its theme. I wanted to re-use most of the existing theme, so I simply edited the files to test the global $table_prefix wherever I wanted different output.
For just two blogs this approach is OK. I’d tidy it up before I added any more.
October 12th, 2007 at 12:24 pm
Hey Alfred. Groovy solution.
I just installed Wordpress twice in order to get 2 databases in 1 site. And then I saw your solution. Which gets me to wondering… Why don’t you have a link to your Portfolio page in your top navigation menu?
Is there a way to dynamically “inter-link” these so that this main site links correctly to the /portfolio/ page and the /portfolio/ menu links back to this main site? Or must one use static, plain html links?
Cheers!
dan
October 12th, 2007 at 1:26 pm
Dan, my menu is hard-coded rather than generated by WordPress; the absence of the portfolio link is for historical reasons - and probably should be fixed.
Your question is a good one. Making the two areas aware of each others menus would be tricky, though not impossible. A plugin which produced a composite menu would seem like a good answer.
One flaw in my solution I didn’t mention above, but discovered since, is that you need to be careful not to let WordPress write to the .htaccess file once it is set up - it can break things! So I set mine as read-only, which means somewhat more effort when a change is required.
October 19th, 2007 at 10:20 pm
Ooh, this looks like just what I’m looking for. I was worried what I wanted might not even be possible, but then I realised that somewhere out there someone would have written it and it looks like I was right
Shall have to give it a try over the weekend. Thanks very much for sharing your code.
Kx
October 20th, 2007 at 12:55 pm
Kathleen, glad to be of help. If you have any problems getting it working, please let me know.
October 22nd, 2007 at 9:16 pm
Thanks for responding and for the offer of help, Alfred.
At first I wanted to try this with an existing blog, where the WP installation is at the root level (well, it’s in the public_html folder, does that count?), so I tried to edit the .htaccess to point to the root, but I must have got that wrong as I got 404 errors.
So now I’ve started afresh with a new installation at another domain, for testing purposes, the original at http://kathleenbright.com/wordpress/, with the ‘portfolio’ one being http://kathleenbright.com/tvt/ However, both are showing the same blog - which is the wordpress one. I looked at the database and only wp_ tables have been created. So it looks like I’ve somehow got errors in my tvt .htaccess and/or my wordpress wp-config.php files Aagh!
Am close to giving up as I’m in way over my head and don’t want to be bugging you with numerous requests to help, especially when I’m so clueless. Would be great if it’s something small I’ve managed to miss by some n00b oversight…!
Thanks again,
Kx
- wordpress/wp-config.php
- tvt/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/tvt$
RewriteRule . /tvt/ [L,R=301]
RewriteCond %{REQUEST_URI} !^/tvt/$
RewriteCond %{REQUEST_URI} !^/tvt/index.php$
RewriteRule ^(.+) /wordpress/$1
October 22nd, 2007 at 10:17 pm
Kathleen, I bet the problem’s in wp-config.php, which didn’t show up due to its content being filtered out. You’d need to run it through a converter to turn it safely into HTML entities (as I did with the code I posted). It’d be quicker if you simply emailed me the files, to alfred (at) likemind (dot) co (dot) uk.
October 28th, 2007 at 10:55 am
Thank you so much; I’ll email it you now.
Kx
January 8th, 2008 at 5:12 am
This is a great bit of code, great explanation and it works like a charm. Thanks!
April 13th, 2008 at 6:01 pm
I have istalled wordpress twice to 2 of its own folders (for 2 seperate blogs)in public html folder, the 1st blog worked well with permalink code being edited in the htaccess file fine, now I have added my second install for my second blog I can’t get pretty permalinks to work etc. My htacces file resides at root of my public html foder but outside both of my blog installs. Like I said all works fine on the first blog, but not on the 2nd once its installed. Is there some code I need to put in the htaccess file or similar please.
Thanks
Awk
April 13th, 2008 at 7:31 pm
Awk, without seeing the content of your .htaccess files I really can’t say what’s happening.
May 6th, 2008 at 4:03 am
[...] Multiple Blogs, One WordPress Install Posted on July 12, 2007 by scoopseven From http://likemind.co.uk/journal/?p=64…; [...]