Monofactor

Home » Blog » Codemaster » Displaying Twitter Feed via Yahoo Pipes

Displaying Twitter Feed via Yahoo Pipes

Twitter API is really busy lately.

That causes delays and performance problems when you try fetching tweets with Twitter API via JSON or other methods.

For that matter, my sidebar tweets widget uses jQuery preload to prevent my whole site to hang until the widget gets a response from Twitter API. But then again there are times that widget gets stuck with the preload phase.

The good news is Yahoo has a great tool that pulls the tweets of a user and swipes @usernames and @comments and returns a clean feed with a fast response.

Using it in WordPress

The following snippet will simply pull the tweets from a given username and result a clean output. It can be used either inside your page/post template or you can create a widget from it.

Lets first fetch the tweets feed:

<?php  
    // Including WordPress RSS feed functions
    include_once(ABSPATH . WPINC . '/feed.php'); 

    /* Using RSS feed from Yahoo Pipes that strips away the @username.  
       Replace [username] with your Twitter username */
    $rss = fetch_feed('http://pipes.yahoo.com/pipes/pipe.run?_id=zncl_xDx2xGVxuG5p2IyXQ&_render=rss&user=[username]');
   
    // The number of tweets to list
    $maxitems = $rss->get_item_quantity(1); 
    $rss_items = $rss->get_items(0, $maxitems); 
?>

And print the tweets with a foreach loop.:

<div class="twitter_tweets">    
   <?php if ($maxitems == 0) echo 'No items';
         else
         // Loop through each feed item and display each item as a hyperlink.
         foreach ( $rss_items as $item ) : ?>
         <a href='<?php echo esc_url( $item->get_permalink() ); ?>'
            title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
            <?php echo esc_html( $item->get_title() ); ?></a><br /> <?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'

   <?php endforeach; ?> 
</div>

We can then style the output but that I leave to you :) Pretty nifty.

Cheers.

Posted in Codemaster, Wordpress

Discuss

2 Comments Posted

Would you like to add one yourself?

+   Add Comment

  1. Tally

    Does this pipe still work for you? I just tried it with my username and nothing happened.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>