Articles Comments

Marco Luthe Online! » WordPress Stuff » How To Add Ping-/Trackbacks When Using Disqus

How To Add Ping-/Trackbacks When Using Disqus

As I mentioned in this post, ping-/trackbacks are not yet supported by Disqus when using the plugin for WordPress. When you export the comments from WordPress, ping-/trackbacks are simply not imported into the Disqus database, yet (they promised that they are working on it).

In the meantime, I managed to add this feature by using the ping-/trackbacks that are stored within the WordPress comments table (mostly, this will be wp_comments).

This is what it looks like (see the original post):

How it’s done:

I wrote a function named DisplayPingTrackbacks() which achieves the goal. In the single.php, I simply put it before comments_template() is called by WordPress, which – in my case – looks like this:

<?php DisplayPingTrackbacks(); ?>

<div id="comments">
	<?php comments_template(); ?>
</div>

Here is what the function looks like (added to the functions.php in the theme’s template directory):

function DisplayPingTrackbacks() {

	// Do not do anything if Disqus is not installed
	if(!dsq_is_installed()) return;

	$current_post_ID = get_the_ID();

	global $wpdb;

	$sql = 	"SELECT comment_author_url, comment_author FROM $wpdb->comments WHERE comment_post_ID = $current_post_ID AND comment_approved = '1' AND (comment_type = 'pingback' OR comment_type = 'trackback') ORDER BY comment_date ASC";

	if ($post_pingtrackbacks = $wpdb->get_results($sql) ) {

		$number_of_pingtrackbacks = count($post_pingtrackbacks);

		if ($number_of_pingtrackbacks == 1) {
			echo "<div id='pingtrackback'><h3 style='font-size:14px;margin-bottom:10px'>One Pingback/Trackback</h3><ul>";
		} else {
			echo "<div id='pingtrackback'><h3 style='font-size:14px;margin-bottom:10px'>" . $number_of_pingtrackbacks . " Pingbacks/Trackbacks</h3><ul>";
		}

		foreach ($post_pingtrackbacks as $post_pingtrackback) {
			echo "\n<li><small><a href='";
			echo $post_pingtrackback->comment_author_url;
			echo "'>";
			$author = $post_pingtrackback->comment_author;
			echo html_entity_decode($author);
			echo "</a>";
			echo "</small></li>";
		}
		echo "</ul></div>";
		}
}

Now, I only hope that ping-/trackbacks are still stored within the WordPress database in the future and that they don’t get lost because of the Disqus plugin…

[Update from 2011-01-03]

It seems like the Disqus Comment System had a major overhaul, which also means that it now shows ping-/trackbacks that are stored in the WordPress comments table. Nice, but I’ll still stick with my aforementioned workaround, since I do not like the formatting of the Disqus system’s built-in solution.

Filed under: WordPress Stuff · Tags: , , , , , , ,

  • tucsonvelo

    So you added the first bit of code to the single.php, but where did you put the actual php function code that tells it what to do?

  • http://www.saphod.net/ Marco

    Sorry, my bad. The function DisplayPingTrackbacks() actually goes into the functions.php which you should be able to locate in your theme's template directory. I'll add this information to the post. Thanks!

  • http://sanitarium.se/ ba

    Thanks man :)

  • http://www.allkins.co.uk Dominic Allkins

    Marco

    Thanks a load… I've just started the blog and have had a couple of trackbacks but couldn't work out why they weren't showing… this should sort it nicely :-)

  • http://somethin-clever.blogspot.com/ Chris Baclig

    Thanks for the info! Your code worked like a charm.

    I've been struggling for the past day trying to figure out why trackbacks weren't working on my company blog. From looking at the HTML source, it looks like the WordPress plugin is actually prepping some JavaScript variables to be used by the Disqus code, but nothing shows up yet. Hopefully this means a fix coming soon…

    Would turning off trackbacks in Disqus be a good idea if using this fix, since WordPress handles trackbacks much more gracefully than Disqus at the moment?

  • http://www.saphod.net/ Marco

    Hi Chris,

    thanks for your feedback, I am glad the code works.

    I think, first, one has to distinguish between trackbacks and pingbacks. Trackbacks are sent when the author of a blog post puts the address of the trackback in the necessary field. I reckon it weighs a little more than a pingback, since pingbacks are sent every time you use a link back to a blog post – you do not have to put a special trackback address in a special field. So, intentionally using a specific address can be considered a bit more “valuable” than just linking to the blog post in your own post, I think.

    Pingbacks and the “normal” WordPress trackbacks are not yet synchronized with Disqus, as I have already reported on my blog. But every post has a special “Disqus trackback address”, meaning that if an author links back to that specific address, trackbacks should also be visible in Disqus. I would leave this option checked.

  • http://jamescooke.info James

    Hi Marco, thanks for this code snip. I've extended some of the formatting used and posted it here : http://fublo.net/post/959432950/getting-pingbac...

    I agree with Chris that turning off trackbacks in Disqus seems to be the best solution at the moment.

  • http://www.saphod.net/ Marco

    Thanks for the mentioning. I turned off trackbacks for Disqus now, also, but I think all it does is hiding the special Disqus trackbacks URI. If you sent a pingback via your post, I never received it, unfortunately. Hope they provide a fix / update for the plugin, soon.

  • http://jamescooke.info James

    Hi Marco – the post on fublo.net is inside disqus which doesn't do trackbacks so that's why you won't have got one :D

  • http://www.saphod.net/ Marco

    Hey guys, it seems they have published a new version of the Disqus plugin which is supposed to support trackbacks as you can read here. There are numerous comments to this updated version on the Official Disqus Blog and also on wordpress.org.

  • http://webolog.net/ Josh

    I Guess i will try this

  • http://www.abhizworld.com Abhi

    I should say that I like your version better than the one provided by Disqus! Thanks for sharing it !

    -Abhi

  • http://blog.fublo.net/2010/08/pingbacks-trackbacks-disqus-wordpress/ Getting pingbacks & trackbacks working with Disqus & WordPress | Fublo Ltd blog

    [...] Use this great code snip from Marco Luthe to show pingbacks on posts. [...]

  • http://scottsdalecomputing.com/display-pingbacks-on-wordpress-posts-with-disqus-comment-system/ Display Pingbacks on WordPress Posts with Disqus Comment System – Scottsdale Computing

    [...] of this code is taken from here: http://www.saphod.net/2010/07/.....ng-disqus/ So I want to give him a shout out. But I took his code and added some additional [...]

  • http://thomasspear.name/ Thomas Spear

    I received your link from the Scottsdale Computing blog post. As Disqus now no longer supports pings/trackbacks, I have found use in the code they borrowed from you and modified. As I hate to make a modification to a theme, in case of theme update or what have you, I have turned this into a plugin on my own site, http://blog.thomasspear.name

    I would like to submit it to the wordpress plugin page, but I would like your permission before I do. I have provided full credit where it is due, in the plugin description, as follows:

    /*
    Description: Shows Pingbacks and Trackbacks above Disqus comments. All credit for the functionality of this plugin remains with the original creator, Marco Luthe, with additional credit to Scottsdale Computing for some format changes. This was originally created as a theme modification. It has been turned into a plugin by myself, Thomas Spear.
    */

    Please let me know if you will be OK for me to submit this to WordPress!

  • Anonymous

    Mentions via twitter are, but not pingbacks or trackbacks. The pingbacks are still being stored in the native WordPress database.

blog comments powered by Disqus