Services Products About Us Case Studies Clients
Modern Signal
Modern Signal Home Page
Lighthouse on beach About Us
Offering a full range of development services: strategy, design, application programming, database development
News & Recents Projects

Setting Up Multiple MangoBlog Instances with Shared Code and Database

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!

Comments

Rick's Globally Recognized Avatar Thanks for this post - it's the first explanation I've seen that offers enough detail so that others can actually get it to work. And it's an elegant solution to boot.

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

David Hammond's Globally Recognized Avatar @Rick, if your main site is ColdFusion-based, it should be pretty easy to include styles from the site in your blog(s). For the site I was working on, I took the GlossyBlue skin and made the changes I needed. In my CMS, the templates are all handled by CFCs, so I just needed to instantiate a CFC within the skin files and call functions to include the header and footer. The specifics are going to depend completely on how your site is set up. I'm not sure why including didn't work for you, since the skin files are all .cfm files which should make it easy to include code.

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

Rick's Globally Recognized Avatar @David, thanks for the reply. I did have the different styles [mapped to] different skin directories [mapped to] entries in the BlOG_blog.skin database column business already figured out. But I'm still a relative novice at complex CFC-based applications, so figuring out exactly what I can do and exactly where in the code I can do it remains a challenge. Anyway, you've given me an idea of something else I can try.

Posted on March 29, 2010 4:25:13 PM EDT by Rick

Topics for this page:

January 2012 --

Charm City Run updates its site to include new Baltimore location. This site-wide project included refreshing header images with photos of customers and events, expanding the site navigation to include a new resources section, and enhancing ways for customers to interact through Charm City Run's many social media channels.

Charm City Run website

October 2011 -- Society for Developmental Biology launches SDB Collaborative Resources (CoRe), an online reference database of peer-reviewed images, movies, and diagrams for learning and teaching developmental biology.
September 2011 -- Millmark launches site for ConceptLinks Inquiry, a subscription-based online curriculum targeted at earth, life, and physical science concepts for grades 2-8.
September 2011 -- The 2012 International Builders’ Show website launches, unveiling the 2012 design and new tools for highlighting community sponsorships, special show events, and featured exhibitors. The site also includes expanded interactive features for attendees and exhibitors, including polls, logistics management tools, and social media.
August 2011 -- Modern Signal awarded contract to rebrand, redesign and develop new phase of PSLawnet.org, a comprehensive directory of legal public sectors jobs postings.