Get Tweets and Display them in Wordpress
<p>All,
I have the following code to retrieve some Tweets:</p>

<pre><code>if( ! $tweet ) {
    $url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&amp;count={$how_many}";
    $curl = curl_init();
    curl_setopt( $curl, CURLOPT_URL, $url );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
    $contents = curl_exec( $curl );
    curl_close( $curl );
    if ( ! empty( $contents ) ) {
        // Decode it.
        $tweet = json_decode( $contents );
        }
    }

    // Check to make sure we have a tweet and display it.
    if ( $tweet ) {
        do_action( 'themeblvd_twitter_slider', $tweet, $options, $username, $slider_id );
    } else {
        $output = 'Twitter timed out.';
    }
    return $output;
</code></pre>

<p>I then have the following code to put them in a Slider:</p>

<pre><code>function themeblvd_twitter_slider_default( $tweet, $options, $username, $slider_id ) {
$tweet = (array)$tweet;
$classes = themeblvd_get_classes( 'slider_standard', true );
$classes .= ' hide-nav_standard';
$classes .= ' show-nav_arrows';
$classes .= ' show-pause_play';

//themeblvd_twitter_slider_js( $slider_id, $options );
?&gt;
&lt;div id="tb-slider-&lt;?php echo $slider_id; ?&gt;" class="slider-wrapper standard-slider-wrapper"&gt;
    &lt;div class="slider-inner&lt;?php echo $classes; ?&gt;"&gt;   
        &lt;div class="slides-wrapper slides-wrapper-&lt;?php echo $slider_id; ?&gt;"&gt;
            &lt;div class="slides-inner"&gt;
                &lt;div class="slider standard-slider flexslider"&gt;
                    &lt;div class="tb-loader"&gt;&lt;/div&gt;
                    &lt;ul class="slides"&gt;
                                &lt;?php
                                foreach($tweet as $t){
                                ?&gt;
                                &lt;li class="slide tight &lt;?php echo $classes; ?&gt;"&gt;
                                    &lt;div class="slide-body"&gt;
                                        &lt;div class="grid-protection"&gt;
                                        &lt;?php
                                        echo '&lt;span class="tweet-icon '.$options['icon'].'"&gt;&lt;/span&gt;';
                                        echo '&lt;a href="http://twitter.com/'.$username.'/status/'.$t-&gt;id_str.'" target="_blank"&gt;';
                                        echo $t-&gt;text;
                                        echo '&lt;/a&gt;';
                                        ?&gt;

                                        &lt;/div&gt;&lt;!-- .grid-protection (end) --&gt;
                                    &lt;/div&gt;&lt;!-- .slide-body (end) --&gt;
                                &lt;/li&gt;
                                &lt;?php
                                }
                                ?&gt;
                    &lt;/ul&gt;
                &lt;/div&gt;&lt;!-- .slider (end) --&gt;
            &lt;/div&gt;&lt;!-- .slides-inner (end) --&gt;                  
        &lt;/div&gt;&lt;!-- .slides-wrapper (end) --&gt;
    &lt;/div&gt;&lt;!-- .slider-inner (end) --&gt;
    &lt;div class="design-1"&gt;&lt;/div&gt;
    &lt;div class="design-2"&gt;&lt;/div&gt;
    &lt;div class="design-3"&gt;&lt;/div&gt;
    &lt;div class="design-4"&gt;&lt;/div&gt;                    
&lt;/div&gt;&lt;!-- .slider-wrapper (end) --&gt;
&lt;?php
}
?&gt;
</code></pre>

<p>This code works about 90% of the time and grabs the tweets based on a username etc. However, about 10% of the time it just rotates without displaying any of the texts. Does anyone see anything or a way that I can make this solution better so that the tweets are always displayed? Is there anything from an error handling perspective that I'm missing that I could add to not display it if it can't retrieve the tweets?</p>

<p>Thanks for any advice in advance.</p>
