Post Pic

How to: Display your number of tweets in full text mode on your WordPress blog

Twitter is obviously a very useful tools for bloggers. Did you ever wanted to know how many times your posts are sent to Twitter by your readers? If yes, just read on and learn how to know it, and display it on your blog, in full text mode.

paste the following function in your functions.php file:

<?php
function tweets($url){
  $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
  $x = new SimpleXmlElement($content);
  $tweets = $x->story->url_count;
  echo "Tweets: ".$tweets;
}

Once done, you can get the number of tweets for any web page you want, for exemple:

<?php tweets("http://www.wprecipes.com"); ?>

To automatically display how many times your posts has been tweet, open the single.php file file and paste the following code:

<?php tweets($post->permalink); ?>

18 Responses

Apr 29 2009 15:20

Cool tip bro !

Apr 29 2009 18:37

Great tip again! You are doing a great job :D

Apr 30 2009 13:39

can I do it while the twitter plugin on?

Apr 30 2009 18:07

I didn’t realised that is so easy. Great recipe again!

May 03 2009 18:29

exactly what I was searching for !!! Thank you for that great piece of code.

May 04 2009 20:06

Wow, this one gets a bit technical, nice one, though.

May 05 2009 02:15

Nice tutorial, thank you!

May 06 2009 20:56

Sounded complicated, but it’s really quite simple. Thanks.

May 08 2009 18:00

That really is very simple to use. I’m always looking for ways to reduce the number of plugins in my blog. I’m going to try this one!

May 14 2009 09:50

I am using this tip right now to my own blog

Thanks

May 24 2009 16:07

Is it code that exactly look like on the bottom on your post? Included bit.ly short url?

May 27 2009 11:01

stupid question, does this go in the theme functions or the wordpress functions page?

Jun 02 2009 11:00

Does it work only with Wordpress blogs? Would it work if I pasted it into a regular website? Just wondering if it’s WP-exclusive.

Jun 02 2009 11:04

@Kotlina: You can use that tip anywhere on a php page, not only WP blogs :)

Jun 16 2009 09:56

Twitter is obviously sweeping the country for both social and friendly outlets and business opportunities. This is a pretty sweet recipe for the blogger and twitter user :D of course it is a bit more technical, but worth it.

Till then,

Jean

Jun 18 2009 03:04

Thanks for the snippet. Its pretty cool :) I was unable to get the changes in single page working due to this line:
$post->permalink

I had to replace that with
get_permalink()

And it worked great ! :)

thanks again!
-dee

Feb 15 2010 14:21

So if you send more than 150 API request per hour, by the end of the hour you’ll get no answer as the of call is limited
A caching system would be very much appreciated ;)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required