New Comment System

The blog now uses a new comment system – Disqus.

I upgraded to BE v2.5, and found various instructions on how to move to Disqus… including these.

There was one problem, however. The instructions state that on post.aspx, JavaScript needs to change to the following:

<script type="text/javascript">
    var disqus_title = '<%=Post.Title %>';
    var disqus_identifier = '<%= Post.Id.ToString() %>';
    var disqus_url = '<%= Post.AbsoluteLink %>';
    var disqus_developer = '<%= BlogEngine.Core.BlogSettings.Instance.DisqusDevMode ? 1 : 0 %>';
    (function () {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://<%=BlogEngine.Core.BlogSettings.Instance.DisqusWebsiteName %>.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>

However, that is not accurate and will result in errors.  The correct code needs to reference Page, and not Post.

<script type="text/javascript">
    var disqus_title = '<%=Page.Title %>';
    var disqus_identifier = '<%= Page.Id.ToString() %>';
    var disqus_url = '<%= Page.AbsoluteLink %>';
    var disqus_developer = '<%= BlogEngine.Core.BlogSettings.Instance.DisqusDevMode ? 1 : 0 %>';
    (function () {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://<%=BlogEngine.Core.BlogSettings.Instance.DisqusWebsiteName %>.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>

If the above is not changed, the blog will throw the following error:

page.aspx(14): error CS0120: An object reference is required for the non-static field, method, or property 'BlogEngine.Core.Post.Title.get'

One more change needs to be done if the above takes place. In archive.aspx.cs, the following line:

comments.InnerHtml = string.Format("<span><a href=\"{0}#disqus_thread\">{1}</a></span>", post.PermaLink, Resources.labels.comments);

needs to change to:

comments.InnerHtml = string.Format("<span><a href=\"{0}#disqus_thread\">{1}</a></span>", post.AbsoluteLink, Resources.labels.comments);

The change above will allow the Archive to correctly display the number of comments and reactions to each post.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.