With the recent site update to TXP Tips, I thought it might be a good idea to use the excellent commenting service Disqus instead of the in-built Textpattern comments system.
Why? For several reasons:
- Easy to integrate – just add some code to your page template/s
- Social sharing, reactions and tagging are included
- Easy to use
- Textpattern’s in-built comments system is hard to customise
One potential downside of hosting your comments on Disqus is just that – any comments added are stored on Disqus rather than in Textpattern. However, given that there is an export tool built into Disqus this may not be a deal breaker.
Attribution
This tutorial was originally put together by maniar over on the forums, using the instructions put together by michaelkpate.
The tutorial is not online anymore so I’ve recreated the steps below.
Getting started
Visit the Presentation tab and create a new page template titled disqus
. Enter the following code and press save.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dsq="http://www.disqus.com/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.0/">
<channel>
<txp:article_custom limit="99999" section="blog" form="disqus-article" />
</channel>
</rss>
Change the section="blog"
attributes as needed – for TXP Tips I used section="blog, articles"
since there were comments in both sections.
Create some forms
Then visit your Presentation > Forms tab and create a new form called disqus-article
and enter the following code:
<txp:if_comments>
<item>
<!-- title of article -->
<title><txp:title no_widow="0" /></title>
<!-- absolute URI to article -->
<link><txp:permlink /></link>
<!-- thread body; use cdata; html allowed (though will be formatted to DISQUS specs) -->
<content:encoded><![CDATA[<txp:body />]]></content:encoded>
<!-- value used within disqus_identifier; usually internal identifier of article -->
<dsq:thread_identifier><txp:article_id /></dsq:thread_identifier>
<!-- creation date of thread (article), in GMT -->
<wp:post_date_gmt><txp:posted gmt="1" format="%F %T" /></wp:post_date_gmt>
<!-- open/closed values are acceptable -->
<wp:comment_status>closed</wp:comment_status>
<txp:comments form="disqus-comments" wraptag="" break="" />
</item>
</txp:if_comments>
Then create another form called disqus-comments
and enter the following code:
<wp:comment>
<!-- internal id of comment -->
<wp:comment_id><txp:comment_id /></wp:comment_id>
<!-- author display name -->
<wp:comment_author><txp:comment_name link="0" /></wp:comment_author>
<!-- author email address -->
<wp:comment_author_email><txp:comment_email /></wp:comment_author_email>
<!-- author url, optional -->
<wp:comment_author_url><txp:comment_web /></wp:comment_author_url>
<!-- comment datetime, in GMT -->
<wp:comment_date_gmt><txp:comment_time format="%F %T" /></wp:comment_date_gmt>
<!-- comment body; use cdata; html allowed (though will be formatted to DISQUS specs) -->
<wp:comment_content><![CDATA[<txp:comment_message />]]></wp:comment_content>
<!-- is this comment approved? 0/1 -->
<wp:comment_approved>1</wp:comment_approved>
<!-- parent id (match up with wp:comment_id) -->
<wp:comment_parent>0</wp:comment_parent>
</wp:comment>
Create a new section
Once the forms have been created, its time to add a new section. Visit the Sections tab and create a section named disqus
and assign it the page template which we created earlier – disqus
.
Visit the new page in the browser
Go to the newly created disqus
section of your website by typing in the URL i.e http://example.com/disqus
. Choose view source and then save the source as imported-comments.xml
or similar name.
Go to Disqus and upload your comments file
Visit your site’s dashboard on Disqus. Click on the “Tools” tab. Go to the ‘Import/Export’ tab and choose Generic (WXR)
to import your file.
If you get a success message that your import went ok, then note that the import process takes quite some time.
In case your import fails
In our case, the TXP Tips import failed. Here are some tips to help you overcome this:
- First, be sure to read the error message associated with the failed import
- Visit the Disqus troubleshooting page for any ideas
- If you get a validation error, try the W3C Validator file service to check for errors
With the TXP Tips export, there were many errors and it appeared they were caused by malformed comments. See this helpful post for more information.
Fixing XML validation errors
In the post above, the author suggests using the the xmllint
UNIX tool which in built into OSX. Open Terminal.app
and enter cd ~/desktop
(assuming you placed the saved XML file on your desktop).
Once in your desktop, enter: xmllint imported-comments.xml
(assuming your file is titled imported-comments.xml).
You may see a lot of errors, here’s what I got first:
imported-comments.xml:3692: parser error : Opening and ending tag mismatch: encoded line 3543 and script
//]]></script></p></content:encoded>
^
imported-comments.xml:3692: parser error : Opening and ending tag mismatch: item line 3531 and p
//]]></script></p></content:encoded>
^
imported-comments.xml:3692: parser error : Opening and ending tag mismatch: channel line 3 and content:encoded
//]]></script></p></content:encoded>
^
imported-comments.xml:4056: parser error : Opening and ending tag mismatch: rss line 2 and item
</item>
^
imported-comments.xml:4060: parser error : Extra content at the end of the document
<item>
^
To fix the problems above, this is what needs to be removed: </script></p>]]>
. With each removal of offending code, I re-saved the imported-comments.xml
then entered xmllint imported-comments.xml
on the command line.
Each time more errors came up, like this:
imported-comments.xml:15891: parser error : Sequence ']]>' not allowed in content
<p><img src="http://img.youtube.com/vi/1ib97f7KONQ/default.jpg" alt="" /></p>]]
^
imported-comments.xml:15891: parser error : internal error
<p><img src="http://img.youtube.com/vi/1ib97f7KONQ/default.jpg" alt="" /></p>]]
^
imported-comments.xml:15891: parser error : Extra content at the end of the document
<p><img src="http://img.youtube.com/vi/1ib97f7KONQ/default.jpg" alt="" /></p>]]
^
This is the offending portion that needed removing from the line number mentioned: ]]>
.
Continue processing the document until Terminal.app returns the entire XML contents. Once that is done, you can re-import your file into Disqus and wait to see what happens!
Thanks for the tip. I've been using Disqus comments on my Txp-powered blog for a couple of years. Works well.
Thanks for sharing this information. I am thinking to integrate Disqus with my blog. Through this blog will not have more spamming links and also we can do conversation with blog followers.
This is great I'm in the process of porting my site to TXP and was thinking about using Disqus.
Do you know if we can use our own web fonts wih Disqus? Typekit google web fonts etc
Anyhow thx for the tut I'm coming back to TXP after a 5 year hiatus man did I miss it!
Hi Matt and welcome back to TXP! Where did you go for the last 5 years - that's a long time!
I've not quite finished with Disqus here on TXP Tips. The documentation at Disqus isn't that good but I did find this link: http://help.disqus.com/cust...
Basically what is supposed to happen is that Disqus inherits your styles but I've found that's not quite working. In our case TXP Tips has 2 style sheets and it doesn't seem to pick up the styles from the main sheet. When I get time I'll investigate further.
I was playing around with other CMS's trying out some custom stuff using SQLite etc. It's funny I was getting extremely frustrated with the lack of flexibility in most CMS's and I picked up my old Textpattern Solutions book and started browsing through it again and decided to check out 4.5.
The new responsive design was nice but man I missed the lean core there's a plugin for everything and I've already written my own for the one I couldn't find.
Regarding Disqus yeah it seems to be using Arial here on my laptop whereas you're using Proxima Nova I believe for your design which is very nice BTW looks great on my Ipad and my Android phone. I'm going with FF Dagny Web Pro for body copy on my next iteration.
Free time is a precious commodity here too I'll have to root around the Disqus site myself once I reach that point.
Hi I was wondering... how do you implement this on an MLP site?
You mean Disqus? I haven't tried but I can't think of any major issues offhand. Give it a go and post back with any problems maybe?
I followed the steps but the disqus page renders nothing. Is it possible that MLP has something to do with it?
Hi Pablo. Sounds like it is but hard to say from here. If the Disqus comments aren't showing up on any pages I'd check first that the embed code is ok and also look at the Disqus admin page to see if any errors are reported there.
If that looks ok then maybe the URL rewriting is throwing off Disqus. It might be worth posting on the MLP thread over at the forums.
As far as I know there is one major problem with disqus on textpattern: you can integrate it (functionality) but posts content is not visible for google and other search engines. Take a look at a source of this page and try to find posts... so we can discuss but it won't be found.
Thats because of the code - disqus provide simple JS to include in the code so the content is only in browser/client side.
Other cms platforms (wp/joomla etc) use disqus native plugins/widgets - those are using php/ajax and disqus content is included as a page content. That's why in my opinion:) you shouldn't use disqus on TXP...
Hi Radek I think you raise some good points about commenting and Textpattern. The in-built commenting system TXP employs isn't too good while Disqus allows us to essentially drop in a solution which generally works.
But as you say having invisible posts for search engines is hardly ideal. I think Destry raised the topic in a forum or Google+ post saying that it might be a good idea for TXP (mag) to move from Disqus to a new Google+ commenting system that was/is being tested (I'm not sure of the status). That might be a good idea but then we'd be tied to Google instead of Disqus as a service not that either is bad in and of itself.
If other CMS platforms offer greater functionality then that speaks of the popularity of the platform rather than Disqus itself which does offer a very good service for free.
What do you do to finish? I'm not good at this stuff and it seems there's a final stage where I need some instructions. I've done everything here but my site is just the same as it was - no Disqus.
Hi James at what point is your install breaking down? Did you follow the tutorial above with all the stages?
Hi Jonathan yes - I've done everything there and all of it works but I don't understand how you insert the disqus comments into txp articles.
Its just a case of embedding the code block from Disqus into your page template or form wherever you want the comments to appear. Hope I understand correctly otherwise maybe you could post a URL and/or your page/form contents to see what's happening.