Lifestream Documentation and Debugging
14 Jun, 2009. Written by Tom Roggero
Hi everybody. As you might know there is a really useful plugin for WordPress called LifeStream from iBegin Labs.
What is it about? You can add a lot of sociable things. I will mention just a few examples, like your RSS feeds of any favourite blog, your Google Reader public sharing items, your Twitter updates, your last.fm last listened songs, your flickr photos, stumbleupon, digg, etc. It is a really complete plugin, in my thoughts, with Sociable, two of the best WP plugins.
I was doing my new lifestream site, when I started looking for this plugin. Because of documentation is not enough, I decided to share what I've learned about.
My idea was to list: last flickr picture, last 3 items shared from Reader, last tweet, and last 3 songs from last.fm
In official documentation there is a piece of code like this:
Well I will add some information about the variables you can pass to it.
Feed types as you can see is an array with string elements that correspond to your feeds. First of all, you have to set them up on WP Administration in order to work. And the list of possible feed_types:
- amazon
- backtype
- blipfm
- bliptv
- blog
- brightkite
- cocomment
- delicious
- deviantart
- digg
- flickr
- foodfeed
- generic
- github
- goodreads
- googlereader
- hulu
- identica
- imdb
- itunes
- jaiku
- kongregate
- lastfm
- librarything
- magnolia
- mixx
- mobypicture
- myepisodes
- myspace
- netflix
- pandora
- photobucket
- picasa
- plurk
- readernaut
- scrnshots
- skitch
- slideshare
- smugmug
- steam
- stumbleupon
- tumblr
- twitpic
- upcoming
- viddler
- vimeo
- wikipedia
- wpcodex
- xboxlive
- yelp
- youtube
- zooomr
limit is precisely how many items do you want to show.
And as limit, feed_types, are values of an array (the get_events passed variable), there are other important fields:
date_interval : it is string, so when you write it on the array you must write 'date_interval'=>'1 month'. Possible values are: X day, X month, X year, X week, etc... where X is an entire number and the word represents elapsed time. This is the one you must use to fix (by default it is just 1 month) when you cannot see any item of a feed.
That's all about building the array variable with items, to show them.
After that, you have to run inside the loop to print out the content.
foreach ($events as $event){ // echo text... }
The foreach function in php is read like "for each item on the $events array, called as $event do..."
So inside the {} (brackets) of foreach, you will use $event to refer the current item. Example:
foreach ($events as $event){ // this will print the SRC for <img alt="" /> of flickr // so you must do something like echo '<img src="'.NEXT_TEXT.'" alt="something" />'; // this is for twitter and some other stuff. // I dont recommend using title instead of description, because title's like "yourusername: yourtweet" // This shows the feed type label (set up on wp lifestream admin) // This one are for Google Reader // And for flickr I used }
Also you can debug and check about other values with var_dump(); php function
Like in the example above:
$events = $lifestream->get_events(array('feed_types'=>array('twitter'), 'date_interval'=>'1 year', 'limit'=>10)); foreach ($events as $event){ }
There you will know about how is the array built.
A common error you might see (because of iBegin typing error):
Parse error: syntax error, unexpected ';' in /document/root/file.php on line 10
To fix this you have to add a closing parenthesis.
Code with error:
$events = $lifestream->get_events(array('feed_types'=>array('twitter'), 'number_of_results'=>1, 'break_groups'=>true);
Code without error:
$events = $lifestream->get_events(array('feed_types'=>array('twitter'), 'number_of_results'=>1, 'break_groups'=>true));
Note for Twitter:
I had found a really good function to use for relative time, thanks to Zachstronaut.
Anything you need, just comment and I will reply ASAP.