Reason: I have a domain and wanted to have more than one blog.
(Specifically written for my pal, Justin Hunt.)
1. We assume the blogs will be created using the following steps:
- Make a sub-domain in your Apache settings.
- Make a database using phpmyadmin or other means.
- Follow the naming conventions below (or something similar).
2. Add this code to your wp-config.php file in above where the normal stuff is stored.
$host = $_SERVER['HTTP_HOST'];
$parts = explode('.',$host);
$domain = $parts;
$db = "wp_" . $domain;
$dbuser = "wp_" . $domain;
/** MySQL hostname */
The “domain” variable is the subdomain prefix (for example “blog.example.com” breaks into an array called “parts” with the “explode” command. Therefore, parts is set to “blog”, parts is “example” and so on.
I used a naming convention with my Wordpress databases in mysql so the database name is “wp_blog” or “wp_<subdomain>” and the user is also the same as the database name. For simplicity the password is always the same no matter which blog I’m using.
3. Once the blog launches, make sure you have made a sub-directory under the wp-content/uploads directory for each sub-domain. This helps to keep the uploaded stuff separate. For example:
Note: Don’t forget to change the Wordpress Settings->Media to reflect where the uploads data gets stored for each blog!
This makes it easy to maintain the blog system software on your site. Once you install a plug-in, the plug-in is there for any blog you have. Same for themes. But uploads are kept separate.