MangoBlog is a sweet (ha ha) ColdFusion-based blog, but it doesn't currently support creating multiple blogs using the same codebase. You can easily make a copy of the code and create another blog that way, but if you're looking at 3, 4, or more blogs, then it's going to start getting out of hand, especially if you want to share the same basic styles for all of the blogs. (Styles can change, of course!)
One thing that I didn't hear suggested on the MangoBlog forums was to simply create a virtual directory on the webserver in order to create another blog using the same code as an existing blog, and that turned out to work really well. I wanted to document the steps I took to set that up for the benefit of my future self and others.
Set up Application.cfc
The first thing is to set up Application.cfc to support multiple blogs. At the top of Application.cfc I added this (my first blog was in a directory called "blog" and all the new ones are in other subdirectories):
this.blogid = ListFirst(cgi.SCRIPT_NAME,"/");
if (this.blogid is "blog"){
this.blogid = "default";
}
Then I included the blogid in the application name:
this.name = "mango_#right(hash(GetDirectoryFromPath(GetCurrentTemplatePath())),50)#_#this.blogid#_v1_4_2";
Then I used that blogID in the OnApplicationStart:
<cfset facade.setMango(createobject("component",variables.componentsPath & "Mango").init(getDirectoryFromPath(GetCurrentTemplatePath()) & "config.cfm",
this.blogid,
getDirectoryFromPath(getCurrentTemplatePath()))) />
With that initial setup, creating a new blog is a 3 step process:
1. Create new blog and blog author records, copying settings from the default blog
The sql below is what I used
DECLARE @blogid nvarchar(32),@basePath nvarchar(32)
SET @blogid = N'new_blog_subdirectory'
SET @basepath = N'/' + @blogid + N'/'
INSERT INTO BLOG_blog (id, title, description, tagline, skin, url, charset, basePath, plugins, systemplugins)
SELECT @blogid, title, description, tagline, skin, replace(url,'/blog/',@basepath), charset, @basePath, plugins, systemplugins
FROM BLOG_blog
WHERE ID = 'default'
INSERT INTO BLOG_author_blog (author_id,blog_id,role)
SELECT author_id,@blogid,role
FROM BLOG_author_blog
WHERE blog_id = 'default' and role = 'administrator'
2. Copy the blog settings in config.cfm
Make a complete copy of the node that starts "<node name="default">" and change "default" to your new blog subdirectory name. Since the config settings for all of my blogs are the same, it would be nice if I could just tell it to use the default configuration, but that doesn't seem to be possible without changes to the MangoBlog code.
3. Create a virtual directory in IIS
Just point the new directory to your original blog directory. I assume that you can do the same thing in Apache, but I don't have much experience with that.
That's it!
Posted on March 24, 2010 3:37:42 PM EDT by David Hammond
I'm curious -- how have you dealt with the implementation of separate styles for multiple blogs that nevertheless share some pieces of code in common with pages elsewhere on the site but outside the blog? In other words, say you want to integrate multiple blogs into an established site and use existing code from it for, e.g., a sitewide navigation bar on the blog pages. I know that I need to create custom themes, but so far anything I've tried to "include" code from outside the blog code directories hasn't worked.
Posted on March 29, 2010 2:26:47 PM EDT by Rick
If you need different styles for different blogs, you could create several skin directories and use the BlOG_blog.skin database field to specify the skin for each blog. In my case, I wanted the same style for all the blogs, so this wasn't an issue.
Posted on March 29, 2010 3:05:09 PM EDT by David Hammond
Posted on March 29, 2010 4:25:13 PM EDT by Rick
Comments have been disabled for this page.