Search

Hi,

I haven’t touched my Symphony driven site for nine months, but are now planning to add some new features. One thing I want to do is using Disqus for commenting on my blog posts. Have anyone used Disqus together with Symphony, and had comments store both at Disqus and in Symphony’s own database?

/Anders

Hi there

I was just wondering if you ever found a solution to this? I was hoping to do the same...

Thanks

Sam

Does it make sense to use a third party service, when commenting functionality is doable with Symphony?

That's subjective. I would say yes.

Integrating Disqus is a simple thing:

Article Identifier

Add a link for the article identifier on the detail page that will be used as a means of both identifying the article in Disqus and as a placeholder for the comments count:

<a href="{$root}/blog/{title/@handle}/#disqus_thread" data-disqus-identifier="article-{@id}">Permalink</a>

Display Comments

Add some logic to display the comments on the detail page:

<xsl:if test="$article and $article != 'category' and not($page)">
    <xsl:call-template name="disqus-comments">
        <xsl:with-param name="id" select="@id" />
    </xsl:call-template>
</xsl:if>

Attach JavaScript to Pages

This template is called on the article detail page:

<xsl:template name="disqus-comments">
    <xsl:param name="id" />
    <div id="disqus_thread"></div>
    &lt;script type="text/javascript">
        var disqus_shortname = '[YOURSHORTNAME]';
        var disqus_identifier = 'article-<xsl:value-of select="$id" />';
        var disqus_url = '<xsl:value-of select="concat($root, '/', $current-page, '/', $article, '/')" />';

        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    &lt;/script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
</xsl:template>

Display Comment Count

On all pages where you need to display the comments count, this JavaScript can be attached to the page. It will look for an anchor with an href attribute containing #disqus_thread to replace with the comments count:

<xsl:template match="data" mode="js">
    &lt;script type="text/javascript">
        var disqus_shortname = '[YOURSHORTNAME]';

        (function () {
            var s = document.createElement('script'); s.async = true;
            s.type = 'text/javascript';
            s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
            (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
        }());
    &lt;/script>
</xsl:template>

Edit: Implemented here.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details