Sidebar Feed Widget showing Tweets, Stumbles, Vids and more

In my sidebar of my personal homepage I show a list of tweets I have done, Links I stumbled on in StumbleUpon, bookmarks I made in delicious and activities in YouTube and this may well be extended soon with some other interesting stuff.



Delicious bookmarks, Tweets and Stumbles are auto posted to my weblog as posts (the delicious sync tool I wrote about takes care of the delicious bookmarks and the other two I will write about some day) and YouTube vids are grabbed from the content of whatever feed.

I made the following widget which I simply include in my functions.php to display that widget. Maybe it is useful for you to:

[cc lang="php"]

/*
* description: Sidebar posts shows a specific set of posts in the sidebar
* based on category ID's
* Note that the main loop should be adjusted to no longer show
* these posts (if you want that)
*
*/
add_action('widgets_init', create_function('', 'return register_widget("EDLSideBarPosts");'));

class EDLSideBarPosts extends WP_Widget {

// some basic services we want to query and show in our sidebar feed:
// (other services post these as postings in our blog automatically)
const icon_delicious = 'http://www.google.com/s2/favicons?domain=delicious.com';
const cat_delicious = 14;
const icon_su = 'http://www.google.com/s2/favicons?domain=stumbleupon.com';
const cat_su = 867;
const icon_twitter = 'http://www.google.com/s2/favicons?domain=twitter.com';
const cat_twitter = 1172;
const icon_youtube = 'http://www.google.com/s2/favicons?domain=youtube.com';

const amount_of_postings = 15;

function EDLSideBarPosts() {
parent::WP_Widget(false, $name = 'Sidebar Posts');
}

/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );

$title = apply_filters('widget_title', $instance['title']);
echo $before_widget; if ( $title )
echo $before_title . $title . $after_title;
$title = apply_filters('widget_title', $instance['title']);
//global $paged see : http://wordpress.stackexchange.com/questions/2466/paging-in-a-sidebar-mini-loop
global $wp_query, $paged;

if ($paged)
{
$pagenumber = $paged-1;
}

$wp_query = new WP_Query();
$categories = (string) self::cat_twitter.",".self::cat_delicious.",".self::cat_su;
$wp_query->set(‘cat’, $categories );
$wp_query->set(‘posts_per_page’, self::amount_of_postings);
$wp_query->set(‘offset’, $pagenumber*self::amount_of_postings);
$posts = $wp_query->get_posts();

if ($posts) :
foreach ($posts as $post) : the_post();
if (in_category(self::cat_delicious))
{
echo $this->createSideBarLine($post, self::icon_delicious, false, true, true);
}
elseif (in_category(self::cat_twitter))
{
echo $this->createSideBarLine($post, self::icon_twitter, false, true, true);
}
elseif (in_category(self::cat_su))
{
echo $this->createSideBarLine($post,self::icon_su,true, true, true);
}
endforeach;
echo ‘

…More on Page ‘;
echo $paged+1;
echo ‘…

‘;

else:
echo “

” . _e(‘Jump to the frontpage for the list’) . ‘

‘;
endif;

echo $after_widget;
}

/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
return $new_instance;
}

/** @see WP_Widget::form */
function form($instance) {
$title = apply_filters(‘widget_title’, $instance['title']);
?>

‘;
$strBuffer.= ‘ $strBuffer.= 'width="12" style="border: 0px none;';
$strBuffer.= 'margin: 0px 10px 0px 0px; display: inline;">‘;
$strBuffer.= ‘
‘;
if ($boolShowTitle) {
$strBuffer.= ‘ $strBuffer.= 'title="Permanent Link to ' . $strTitle . '">‘;
$strBuffer.= $strTitle . “
“;
}
if ($boolShowExcerpt) {
$strBuffer.= $post->post_excerpt;
}
if ($boolShowContent) {
$strBuffer.= $strContent;
}
if (is_admin())
{
$strBuffer.= ‘‘;
$strBuffer.= ‘ [edit]
‘;
}
$strBuffer.= “

“;
return $strBuffer;
}
}
?>
[/cc]

If you want to exclude these categories from the main loop simply add

[cc]
global $wp_query;
$wp_query->set(‘cat’, ‘-14,-1172,-867′);
$wp_query->set(‘posts_per_page’, 12);
$posts = $wp_query->get_posts();
[/cc]

before the main loop.