Combining Twitter and Wordpress Comments

May 3rd, 2009 | 11 Comments | Posted in General Techologies

Yesterday I had the crazy of idea of reviving my long dormant blog and tweeted that. Immediately Rich Miller (@rhm2k) had a great suggestion.

rhm2k_twitcomment_suggestion.png

Unfortunately, after looking around a bit, I couldn’t find any existing solution to do this. So I decided to hack my own. This hacked up solution is based on a slightly modified version of Twitpress and a new module I hacked up called Twitcomments. The basic idea is to have Twitpress tweet the blog post as it was designed to do, but adding a unique hashtag to the end of that tweet. Then add a section to the blog post to display the Twitter search results of this unique hashtag. For me it’s right below the blog post but before the normal blog comments.

So below is the steps to recreate what I have on Zen 2.0.

  1. Modify Twitpress to add a parameter for [postid]. The line I added to Twitpress 0.3.2 is line 250.
    $proto = str_replace( "[permalink]", $post->guid, $proto );
    $proto = str_replace( "[postid]", $postID, $proto );
    $proto = str_replace( "[link]", get_option( 'home' )."?p=".$postID, $proto );
    

    This essentially allows me to put “[postid]” (without quotes) in the Twitpress configuration. Mine looks like this

    New blog: [title] [permalink] #zen[postid]

    So when Twitpress post to Twitter, the actual tweet will look like this:

    zen284_tweet.png

    Note the “#zen284″ hashtag? That’s hashtag that I will later on use to search for any comments related to this post. The hope is that people would carry this throughout the conversation.

  2. To allow a bit more flexibility, you can add a few more lines to Twitpress so it will add additional hashtags based on the meta information associated with the post. To do that, add the following lines (for me this starts at line 254 below all the str_replace calls):
    $hashtags = get_post_meta($postID, "Hashtags", true);
    if ($hashtags) {
    	$proto .= " " . $hashtags;
    }

    And in the blog post, you can add a custom field with the name “Hashtags” and some value. For this blog post, I added “#csaguide”. The value of “Hashtags” will be added to the Twitpress tweet.

  3. To add the twitter search to each of the blog posts, you need to download my hacked up plugin Twitcomments and put it under the directory “wp-content/plugins/twitcomments”. Make sure you rename “twitcomments.txt” to “twitcomments.php”.

    In addition, you need to download SimplePie and copy “simplepie.inc” in the same directory. SimplePie is used for parsing the twitter search result, which is in ATOM format.

    You will also need to update twitcomment.php and change “#zen” to whatever you set your unique hashtag prefix to be.

    Once you have done all that, make sure you go into WP’s plugins page and activate Twitcomments.

  4. The last thing you need to do is add a function call to your theme’s single.php.
    <?php twitcomments(); ?>

    Add this to wherever you like your twitter comments to appear. Once you do that, you should see something like the following when you go to your post.

    WP_Twitcomments.png

    You can go to this post to see an example of this in action.

That’s it. I know it’s not pretty the way I’ve written it up. If someone wants to take this, modify it so it’s configurable through WP, and package it up nicely, please feel free to do so. You can consider my hacked up plugin to be New BSD licensed.

Enjoy!

Tags:

Twitter Comments for "#zen295 OR #wordpress"

  1. WPMU.ORG: RT @apeatling: Interested in some feedback for BuddyPress 1.3 dev ideas: http://bit.ly/9ayvuJ #buddypress #wordpress

  2. Best WP Plugin: Plugin Review: OIO Publisher http://tinyurl.com/yfvue7h #wordpress #plugin

  3. Freelancer.com: Custom Update to Existing Website on #Wordpress http://bit.ly/alWiYs #freelance #jobs #css #php #wordpress

  4. Freelancer.com: #Website Design and Redesign http://bit.ly/9mmbtn #freelance #jobs #ecommerce #graphicdesign #websitedesign #wordpress

  5. Wordpress Jobs: Redesign a very poorly CMS Wordpress site. | Elance Job http://bit.ly/cpbC0K #WordPress #Jobs

  6. lighans: He, ik zie dat versie 3.0 van #wordpress heel interessant gaat worden. Nog een maand wachten.... (en welterusten)

  7. diana guay: Also a #wordpress Meetup in Northampton Mass this week. I DEFINITELY need to know more wordpress.

  8. Alex Kühnel: kennt ihr den Color Scheme Designer? Coole Sache! http://www.colorschemedesigner.com/ #wordpress #css #html

  9. Web Design Magazine: Sonica Free Premium Wordpress Theme http://bit.ly/9Q142z #wordpress #wp

  10. Stephan Schmatz: 20 Beautiful Minimalist WordPress Themes http://ow.ly/1liD8 #wordpress #themes


More twitter comments...
Follow Discussion

11 Responses to “Combining Twitter and Wordpress Comments”

  1. sulumits retsambewNo Gravatar Says:

    great tutorial thanks for sharing.

  2. TryBPONo Gravatar Says:

    Much love to you for putting this together, that’s awfully useful. The more tools I have to connect Twitter and the blog, the better, IMO.

  3. latogaNo Gravatar Says:

    Great tutorial on integrating these. I’m actually shocked that there wasn’t a plugin already to do this on WordPress. Threaded discussions is one of the failings of twitter and why FriendFeed has taken off with a lot of people…

  4. CarlozMorrisNo Gravatar Says:

    I guess this is going to become less actual because of the world financial depression, what do you think?

  5. Twitter TrendsNo Gravatar Says:

    Works great. Thank you!

  6. bodydetoxNo Gravatar Says:

    Twitter is very addictive. I like Twitter more than blogging. the messages are short and straight to the point.

  7. Over 50 datingNo Gravatar Says:

    This is great, i wish twitter had threaded messages… would be odd to intergrate it though.

  8. Social Bookmarking SitesNo Gravatar Says:

    Nice tutorial,maybe i will add this to my blog.

  9. acnetreatmentsguyNo Gravatar Says:

    i really love to use Twitter. i was addicted to Blogging before the birth of Twitter. Now i am addicted to Twitter.

  10. BobNo Gravatar Says:

    Good article. Plenty of detail and definitely a worthy bit of social networking goodness.

  11. Farmville TricksNo Gravatar Says:

    Really nice plugin, I use it on all my blogs now. Thanks!

Leave a Reply