Merging multiple Twitter feeds

Jason Bobich edited this page Jun 24, 2013 · 9 revisions

Explanation coming soon...

Creating a function that utilizes Tweeple's default template for displaying Tweets.

function my_tweets() {

    // Get Twitter feeds.
    $feed_1 = tweeple_get_feed( 1 );
    $feed_2 = tweeple_get_feed( 2 );
    $feed_3 = tweeple_get_feed( 3 );

    // Check for any errors with any of the three feeds.
    if( tweeple_error( $feed_1 ) || tweeple_error( $feed_2 ) || tweeple_error( $feed_3 ) ) {
        echo '<p>There was an error.</p>';
        return;
    }

    // Get Tweets
    $tweets = tweeple_get_tweets( array( $feed_1, $feed_2, $feed_3 ) );

    // Do you want the timestamp (i.e. "Details") displayed 
    // for this merged feed?
    $options = array( 'time' => 'yes' );

    // Use default template to display Tweets.
    tweeple_display_default( $tweets, $options );

}

Setting up a completely custom function and custom display.

function my_tweets() {

    // Get Twitter feeds.
    $feed_1 = tweeple_get_feed( 1 );
    $feed_2 = tweeple_get_feed( 2 );
    $feed_3 = tweeple_get_feed( 3 );

    // Check for any errors with any of the three feeds.
    if( tweeple_error( $feed_1 ) || tweeple_error( $feed_2 ) || tweeple_error( $feed_3 ) ) {
        echo '<p>There was an error.</p>';
        return;
    }

    // Get Tweets
    $tweets = tweeple_get_tweets( array( $feed_1, $feed_2, $feed_3 ) );

    if( count( $tweets ) > 0 ) {

        // We have Tweets; so loop through and show 'em.
        foreach( $tweets as $tweet ) {
            // $tweet['text'] ...
            // $tweet['time'] ...
        }

    } else {

        // Display error
        echo '<p>No Tweets to display.</p>';

    }

}