As a blogger it's great to be able to share your thoughts with the universe. It's even better when the universe talks back! On a serious note blog comments are a great way to get feedback on your ideas and get some robust discussion going. This is how I set them up, for my blog engine, using Disqus.

I'm assuming you know what Disqus is, if not go and read about it here. Needless to say it's an awesome tool to build a community around your blog. It's also dirt easy to get setup on your blog as it's just a javascript embed code.

Getting Disqus Setup

As I said it's dirt easy getting setup with Disqus.

  1. Sign up for a Disqus account. This will also allow you to post comments on blogs that use Disqus.
  2. Login to your Dashboard and click on the "Add Disqus to Site" link under your profile menu.
  3. Configure the settings you want.
  4. Go to the 'Install' tab underneath settings and select the 'Universal Code' option.
  5. Follow the instructions.

This is not a detailed post on how to get Disqus up and running so if you have problems getting it setup Google is your friend :)

Integrating Disqus with BlogMatrix

The easiest way to use the Disqus javascript embed code would be to put it in my main Layout file layouts/_SiteLayout.cshtml. However this would result in a comments section appearing on every page of my site. Not exactly what I want!

Instead I created a new Layout file layouts/_BlogLayout.cshtml which contained the following:

     Layout = '~/layouts/_SiteLayout.cshtml';
@if(Page.ShowComments == true) {

The key line in the code listing above is the Page.ShowComments == true if statement. The /partials/_Disqus.cshtml file simply contains the Disqus javascript embed code and isn't anything really special.

Each blog post has a configuration section where the Layout file can be specified and any other values set. This is an example of the configuration section for this blog post. You'll notice the new layout file layouts/_BlogLayout.cshtml is used on the first line and the Page.ShowComments value being set on the last line:

    Layout = '~/layouts/_BlogLayout.cshtml';
    // 00017.json
    var metadata = PostMetaData.GetPostMetaData(Server.MapPath('~/_postmetadata/00017.json'));
    Page.Title = metadata.title;
    Page.Meta_Description = metadata.meta_description;
    Page.ShowComments = true;


By setting up my blog posts with a separate Layout file I'm able to maintain control over which pages have comments and which don't. That's one of the beauties of rolling your own custom blog engine. You can do whatever you want :)

But most importantly by using Disqus I'm able to get discussions up and running extremely quickly without having to write any serious code.

So send me a quick comment below!

comments powered by Disqus