I’m sure you’ve seen websites with a little shout-out bubble with the latest tweet.
Maybe I’m just Old School, but I think it’s awesome and a lot of fun. I really want to add it to my own site, and now with this latest piece of code from Cats Who Code, I can!
I run my site on WordPress, so I could obviously just throw on my latest tweet widget, but I want to creatively embed it into my theme. That’s the great thing about this code.
First, drop this bit into your functions.php or into your own functionality plugin:
[cc lang=”php”]function get_status($twitter_id, $hyperlinks = true) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, “http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1”);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$src = curl_exec($c);
curl_close($c);
preg_match(‘/(.*)/’, $src, $m);
$status = htmlentities($m[1]);
if( $hyperlinks ) $status = ereg_replace(“[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]”, ‘\\0‘, $status);
return($status);
}[/cc]
After you’ve done this, adding it into your theme is super simple:
[cc lang=”php”]echo get_status(‘catswhocode’);[/cc]
As quick and easy as this is, it’s the CSS you’ll have to toy around with the most.
If you drop this onto your site, be sure drop us a link in the comments so we can see what you’ve done!
[via Cats Who Code]
Speak your mind...