Many people have asked me how I embedded the available Lifestream plugins (or code) so that it looks like mine at h4×3d.com/lifestream
Many seem to struggle with the (yet) simple set-up or use the wrong (and buggy) files.
Since the Lifestream I use is a mixture of different Lifestream plugins and it is all open-source, I would like to lift some secrets and share my knowledge with you.
My resources include Jeremy Keith’s Lifestream plugin code (at the bottom), Elliot Back’s Lifestream code (that did not work correctly), this article, a blog dedicated to Lifestreams and last but not least Gunnar Þór Hafdal – the Lifestream godfather. I was lucky to pick-up his code. I removed some items here and there, but in general he did 99,9% of the work, thank you!. I wonder why he took down his Lifestream and the code samples? They were great.
Below you will find the code, please note that the Wordpress Plugin integration does not work, you will have to hand-code the variables such as FlickrRSS etc in the life.php itself.
NOTE: You need to run a quick CTRL+H (find and replace) for the < ?php... the code-markup on this page is that way so it does not break anything. You need to finalize the script yourself by changing all instances of < ?php back to the original (delete the blank space)
Life.php (goes in Theme folder)
< ?php
/**
* Class for the 'Lifestream' page, ala
* the Cool One (Jeremy Keith).
* Nothing to fancy here, just setting up
* some default Streams, and adding them
* as options to the WP Options table.
**/
include_once (dirname(dirname(dirname(dirname(__FILE__)))) . "/wp-config.php");
class life {
function defaultStreams() {
// To add another service to the system, simply
// add it to this handy, dandy array().
return array(
'life_twitter' => 'http://feeds.feedburner.com/Twitter/h4x3d',
'life_blog' => 'http://feeds.feedburner.com/jez',
'life_flickr' => 'http://api.flickr.com/services/feeds/photos_public.gne?id=29642584@N00&format=rss_200',
'life_delicious' => 'http://feeds.feedburner.com/Delicious/h4x3d?format=xml',
'life_lastfm' => 'http://ws.audioscrobbler.com/1.0/user/h4x3d/recenttracks.rss',
'life_digg' => 'http://digg.com/rss/jizz/index2.xml',
'life_cocomment' => 'http://www.cocomment.com/myrss2/jez.rss'
);
}
function checkStreams() {
if( get_option( 'life_installed' ) ) {
} else {
self::install();
}
}
function install() {
add_option( 'life_installed', '1', "" );
add_option( 'life_version', '1.0', "");
foreach ( self::defaultStreams() as $key => $value ) {
add_option( $key, $value, "" );
}
/* echo 'Installed, ready to go.' */;
}
function upgrade() {
foreach ( self::defaultStreams() as $key => $value ) {
if( !get_option( $key ) ) {
add_option( $key, $value, "" );
echo 'Added ' . $key;
}
}
}
function loadStreams() {
foreach( self::defaultStreams() as $key => $value ) {
// find the values for each of our streams (RSS Feeds)
if( get_option( $value ) ) {
$value = get_option( $value );
} else {
echo '
' . $key . ': ' . $value . ' not found in the database.
';
}
}
}
}
life::checkStreams();
?>
Another file
Stream.php (goes in Theme folder)
< ?php
/**
* Template Name: Lifestream
* Template for the 'Lifestream' page, ala
* the Cool One (Jeremy Keith).
* Uses built in WP technologies (MagPIE and Snoopy),
* plus some CJD elbow Grease.
* Some modifacation by Gunnar Hafdal
**/
require_once( ABSPATH . WPINC . '/rss-functions.php' );
include_once( TEMPLATEPATH . '/life.php' );
?>
< ?php
get_header();
?>
(legend of tags)
< ?php if (have_posts()) : ?>
< ?php while (have_posts()) : the_post(); ?>
">< ?php the_title(); ?>
< ?php edit_post_link(); ?>
< ?php the_content('
Continue reading this article'); ?>
< ?php
//date_default_timezone_set("Europe/Copenhagen"); // timezone, doesn't work at the moment
define('MAGPIE_CACHE_AGE', 10*10); // ten minutes, I think.
$details = array('title','link');
$list = array();
foreach ( life::defaultStreams() as $name => $feed ) {
$rss = @fetch_rss( $feed );
$items = $rss->items = array_slice( $rss->items, 0 );
foreach ($items as $item ) {
$date = strtotime( substr( $item['pubdate'], 0, 25 ) );
// This fixes the time error that the "date_default_timezone_set" should fix
// Set it as $date += 3600*1; to add 1 hour or $date -= 3600*1; to remove 1 hour
// I think it's based around the UTC time
$date += 3600*2;
$list[ $date ][ "name" ] = $name;
foreach ($details as $detail) {
$list[$date]['title'] = $item['title'];
$list[$date]['link'] = $item['link'];
}
}
}
krsort( $list );
$day = '';
foreach ( $list as $timestamp => $item ) {
$this_day = date("F jS",$timestamp );
if ( $day != $this_day ) {
?>
< ?php echo $this_day; ?>
< ?php $day = $this_day; } ?>
">
" alt="< ?php echo $item["name"]; ?>" />
">
< ?php echo date("g:ia",$timestamp); /* the "g:ia" tell the "date" function to output e.g. 7:37am */ ?>
(special code goes here, see below)*
< ?php
}
?>
< ?php endwhile; else: ?>
Sorry, no posts matched your criteria.
< ?php endif; ?>
< ?php get_sidebar(); ?>
< ?php get_footer(); ?>
*Special code, it breaks the display, type it down yourself in order to make it work. Don’t be lazy :)
1 <a class=”url summary” href=”< ?php echo $item["link"]; ?>”>< ?php echo $item["title"]; ?></a>
Again Credits go to Gunnar, he’s the man
If you enjoyed this post, make sure you subscribe to my RSS feed!
Related posts:
- Wordpress Themeviewer opened again Hooray fo
- Wordpress 2.8-beta1-11402 Quite fran
Tagged with: lifestream • stream your life • Wordpress



9 Comments
Jump to comment form | comments rss [?] | trackback uri [?]