- Marco Luthe Online! - http://www.saphod.net -

How To Add Ping-/Trackbacks When Using Disqus

Posted By Marco On July 9, 2010 @ 22:07 In WordPress Stuff | No Comments

As I mentioned in this post [1], ping-/trackbacks are not yet supported by Disqus [2] when using the plugin for WordPress [3]. 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 [4]):

[5]

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.


Article printed from Marco Luthe Online!: http://www.saphod.net

URL to article: http://www.saphod.net/2010/07/09/how-to-add-ping-trackbacks-when-using-disqus/

URLs in this post:

[1] this post: http://www.saphod.net/2010/06/25/disqus-comments-not-yet-working-with-ping-trackbacks/

[2] Disqus: http://www.disqus.com

[3] plugin for WordPress: http://wordpress.org/extend/plugins/disqus-comment-system/

[4] original post: http://www.saphod.net/2009/01/28/call-to-undefined-function-get_currentuserinfo/

[5] Image: http://www.flickr.com/photos/marcoluthe/4778071952/