Introduction

This class eliminates common difficulties when trying to display Tweets on your website or web application. Most methods of loading Tweets are effective, but unfortunately limited when it comes to customization. With this class, you're able to design your own feed. With a little bit of pre-existing knowledge of HTML you're also able to create your own format without editing any code in the class.

Features

Customization

With over 30 options to choose from, and a custom formatting feature this class has endless possibilites.

Conservation

This class caches feed data to save bandwidth for both you and Twitter, resulting in faster load times.

Efficiency

Methods used in this class have been proven to be faster than most traditional methods. Efficiency is key when running a successful website.

Ease of Use

Implementation of this class is a breeze. Don't hassle with getting things to work when it only takes a couple steps to install.

Emoji Support

Detect Emoji characters made popular on mobile devices such as iPhone or Android and replace them with their respective icon viewable on web.

Search Support

Use Twitter's search API as well as many other endpoints.

Multiple Screen Names

Display multiple screen names in a single feed. The class automatically puts the tweets in chronological order. This applies for any endpoint that supports it, such as Search.

1. Create Twitter Application

Twitter's API v1.1 requires all transactions to be authorized by user context. This means that in order to use this script you will need to create a Twitter application to obtain a consumer key, consumer secret, access token, and access token secret. These are used to authenticate your application via oAuth.

After logging into https://www.dev.twitter.com/, navigate to https://dev.twitter.com/apps/new and enter the requested information.

Create an application

Once you have successfully created an application, navigate to the bottom of the page and click "Create my access token". This is required to query for a user's tweets on their timeline.

Create my access token

And you're done! You can view your keys on the "Details" tab of your application.


2. Include Files

In this zip, you should have the folder src/. This includes the Twitter class as well as other files needed in order for this script to work. Copy that folder relative to your php file. Finally, include the class.

require_once 'src/ultimate.twitter.feed.php';

3. Construct Class

Next, we're going to construct a new instance of the Twitter class. The example below shows the options required to be passed into the constructor function. You can find where to get your keys in the first step.

Note that the option screen_name and user_id are interchangeable. Meaning that one must be passed, but not both.

$options = array(
    'screen_name' => 'MyScreename',
    'consumer_key'  => 'CONSUMER KEY',
    'consumer_secret' => 'CONSUMER SECRET',
    'user_token' => 'ACCESS TOKEN',
    'user_secret' => 'ACCESS TOKEN SECRET',
);

$twitter = new Twitter($options);

4. Print a Feed

Finally, you can print a users Tweet feed. The class uses the options provided to format each tweet.

$twitter->PrintFeed();

Optionally you can pass a callback function to PrintFeed() which will be called with each tweet. The function is pushed with the tweet object for the given tweet.

function myCallback($tweet) {
    echo $tweet['text'];
}

$twitter->PrintFeed('myCallback');

That's it! You can view the various options and settings this class provides here.

Class Options

These options are available to use during the life of a class instance. In addition to passing an array to the class constructor function, there are available getter/setter functions. Refer to the following example on how to use them.

//get the 'screen_name' option from the instance '$twitter'
echo $twitter->option('screen_name');

//set the option 'screen_name' to 'CodeCanyon' for the instance '$twitter'
$twitter->setOption('screen_name', 'CodeCanyon');
Default Functionality
Toggle Source
CSS
.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}
PHP
$options = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
);

$twitter = new Twitter($options);

$twitter->PrintFeed();
Disable Auto Replacing Links
Toggle Source
  • Testing Emojis - 😄😃💎👽
  • Media test http://t.co/G7qkF549
  • This is testing out #hashtags. #use #as #many #as #you #like.
  • You can @mention @anyone you like.
  • Link test - http://t.co/3wQJpBIi
  • The ability to upload, remove, and retrieve profile banner images is now available for API v1.1. https://t.co/MtuaToSo ^TS
CSS
.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}
PHP
$opts = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'detect_mentions' => false,
    'detect_hashtags' => false,
    'detect_links' => false
);

$twitter = new Twitter($opts);

$twitter->PrintFeed();
Detecting Emojis
Toggle Source
CSS
/**
* -- NOTE --
* You must include "src/emoji.css" into your document for the icons to display
*/

.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}
PHP
$opts = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'detect_emojis' => true
);

$twitter = new Twitter($opts);

$twitter->PrintFeed();
Adding Relative Time
Toggle Source
CSS
.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}

.tweet-container li .time {
    margin: 5px 0 0 2px;
    font-size: .8em;
    color: #bebebe;
}
PHP
$format = '<li> {tweet:text} <div class="time"> {tweet:relative_time} </div> </li>';
$format_retweet = str_replace('<li>', '<li class="retweet">', $format);

$options = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'format' => $format,
    'format_retweet' => $format_retweet
);

$twitter = new Twitter($options);

$twitter->PrintFeed();
Adding Profile Pictures
Toggle Source
CSS
.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}

.tweet-container li .time {
    margin: 5px 0 0 2px;
    font-size: .8em;
    color: #bebebe;
}
.tweet-container li .profile-pic {
    width: 36px;
    height: 36px;
    position: absolute;
    top: 10px;
    left: 5px;
    border-radius: 5px;
}
PHP
$format = '<li class="pic"> <img src="{tweet:user:profile_image_url}" class="profile-pic" /> {tweet:text} <div class="time"> {tweet:relative_time} </div> </li>';

$format_retweet = str_replace('<li class="pic">', '<li class="pic retweet">', $format);

$opts = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'format' => $format,
    'format_retweet' => $format_retweet
);

$twitter = new Twitter($opts);

$twitter->PrintFeed();
Using a Callback Function
Toggle Source
CSS
.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}

.tweet-container li .time {
    margin: 5px 0 0 2px;
    font-size: .8em;
    color: #bebebe;
}
.tweet-container li .profile-pic {
    width: 36px;
    height: 36px;
    position: absolute;
    top: 10px;
    left: 5px;
    border-radius: 5px;
}
PHP
function myCallback($tweet) {
    echo '<li class="pic', ($tweet['is_retweet'] ? ' retweet' : '') ,'">
            <img src="', $tweet['user']['profile_image_url'] ,'" class="profile-pic" />
            ', $tweet['text'] ,'
            <div class="time">
                ', $tweet['relative_time'] ,'
            </div>
        </li>';
}

$opts = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
);

$twitter = new Twitter($opts);

$twitter->PrintFeed('myCallback');
Detecting Media Using a Callback Function
Toggle Source
CSS
.tweet-container {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.tweet-container li {
    padding: 10px 5px;
    border: 1px solid #d4d4d4;
    border-top: none;
}

.tweet-container .retweet {
    padding-left: 26px;
    background: url(../Images/retweet.png) 5px center no-repeat;
}

.tweet-container li:first-child {
    border-top: 1px solid #d4d4d4;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.tweet-container li:last-child {
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}

.tweet-container li:nth-child(odd) {
    background-color: #f1f1f1;
}

.tweet-container li a {
    font-weight: normal;
    color: #303030;
}

.tweet-container li .time {
    margin: 5px 0 0 2px;
    font-size: .8em;
    color: #bebebe;
}
.tweet-container li .profile-pic {
    width: 36px;
    height: 36px;
    position: absolute;
    top: 10px;
    left: 5px;
    border-radius: 5px;
}

.tweet-container li img:not(.profile-pic) {
    margin: 10px 0 5px 0;
    max-width: 720px;
}
PHP
function detectMedia($tweet) {
    echo '<li class="pic', ($tweet['is_retweet'] ? ' retweet' : '') ,'">
            <img src="', $tweet['user']['profile_image_url'] ,'" class="profile-pic" />
            ', $tweet['text'];

        if(isset($tweet['entities']['media'])) {
            foreach($tweet['entities']['media'] as $i => $obj) {
                if($obj['type'] == 'photo') {
                    echo '<img src="', $obj['media_url'] ,'" alt="Twit Pic" />';
                    break;
                }
            }
        }

    echo '<div class="time">
            ', $tweet['relative_time'] ,'
          </div>
        </li>';
}

$opts = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '....',
);

$twitter = new Twitter($opts);

$twitter->PrintFeed('detectMedia');
Twitter Style
Toggle Source
CSS
.twitter-style {
    margin: 0;
    padding: 0;
    list-style-type: none;
    background: white;
    border: 1px solid #eeeeee;
    color: #333333;
    border-radius: 6px;
}

.twitter-style .heading {
    color: #333333;
    padding: 12px;
    height: 20px;
    font-size: 18px;
    font-weight: bold;
}

.twitter-style li {
    border-top: 1px solid #e8e8e8;
    padding: 9px 12px;
    position: relative;
    line-height: 18px;
}

.twitter-style li:hover {
    background: #f5f5f5;
}

.twitter-style li img {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 48px;
    height: 48px;
    border-radius: 5px;
}

.twitter-style li a {
    color: #0084B4;
    font-weight: normal;
}

.twitter-style li .content {
    position: relative;
    margin-left: 58px;
    min-height: 51px;
}

.twitter-style li .content .user .username {
    font-weight: bold;
    font-size: 14px;
    color: #333333;
}

.twitter-style li .content .user .screenname {
    font-size: 12px;
    color: #999999 !important;
}

.twitter-style li .content .user a {
    text-decoration: none;
    font-weight: normal !important;
}

.twitter-style li .content .user a:hover .username {
    text-decoration: underline;
}

.twitter-style li .content .user small {
    color: #bbbbbb;
    font-size: 12px;
}

.twitter-style li .content .time {
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 12px;
}

.twitter-style li .content .time a {
    text-decoration: none;
    font-weight: normal !important;
    color: #999999;
}

.twitter-style li .content .time a:hover {
    text-decoration: underline;
    color: #0084B4;
}

.twitter-style li .content .retweet {
    margin-top: 5px;
    padding-left: 20px;
    color: #999999;
    font-size: 12px;
    background: url(../Images/retweet.png) left center no-repeat;
}
PHP
function twitterStyle($tweet) {
    $timestamp = strtotime($tweet['created_at']);

    list($date, $year) = array(date('j M', $timestamp), date('y', $timestamp));

    if($year != date('y'))
        $date .= (' '. $year);

    echo '<li>
        <img src="', $tweet['user']['profile_image_url'] ,'" />
        <div class="content">
            <div class="user">
                <a href="https://www.twitter.com/', $tweet['user']['screen_name'] ,'">
                    <span class="username">', $tweet['user']['name'] ,'</span>
                    <span class="screenname">
                        <small>@</small>', $tweet['user']['screen_name'] ,'
                    </span>
                </a>
            </div>
            <div class="time">
                <a href="', $tweet['twitter_link'] ,'"> ', $date ,' </a>
            </div>
            <div class="text"> ', $tweet['text'] ,' </div>
            ', ($tweet['is_retweet'] ? '<div class="retweet"> Retweeted by '. $tweet['retweeter']['name'] .' </div>' : ''),'
        </div>
    </li>';
}

$options = array(
    'screen_name' => 'FeedTestUser',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'html_before' => '<ul class="twitter-style"> <div class="heading"> Tweets </div>',
);

$twitter = new Twitter($options);

$twitter->PrintFeed('twitterStyle');
Live Search Ticker
Toggle Source
    Results for "Programming"
CSS
.search-ticker {
    margin: 0;
    padding: 0;
    list-style-type: none;
    background: white;
    border: 1px solid #eeeeee;
    color: #333333;
    border-radius: 6px;
}

.search-ticker .heading {
    color: #333333;
    padding: 12px;
    height: 20px;
    font-size: 18px;
    font-weight: bold;
}

.search-ticker li {
    border-top: 1px solid #e8e8e8;
    padding: 9px 12px;
    position: relative;
    line-height: 18px;
}

.search-ticker li:hover {
    background: #f5f5f5;
}

.search-ticker li img {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 48px;
    height: 48px;
    border-radius: 5px;
}

.search-ticker li a {
    color: #0084B4;
    font-weight: normal;
}

.search-ticker li .content {
    position: relative;
    margin-left: 58px;
    min-height: 51px;
}

.search-ticker li .content .user .username {
    font-weight: bold;
    font-size: 14px;
    color: #333333;
}

.search-ticker li .content .user .screenname {
    font-size: 12px;
    color: #999999 !important;
}

.search-ticker li .content .user a {
    text-decoration: none;
    font-weight: normal !important;
}

.search-ticker li .content .user a:hover .username {
    text-decoration: underline;
}

.search-ticker li .content .user small {
    color: #bbbbbb;
    font-size: 12px;
}

.search-ticker li .content .time {
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 12px;
}

.search-ticker li .content .time a {
    text-decoration: none;
    font-weight: normal !important;
    color: #999999;
}

.search-ticker li .content .time a:hover {
    text-decoration: underline;
    color: #0084B4;
}

.search-ticker li .content .retweet {
    margin-top: 5px;
    padding-left: 20px;
    color: #999999;
    font-size: 12px;
    background: url(../Images/retweet.png) left center no-repeat;
}
HTML
<ul class="search-ticker">
    <div class="heading"> Results for "Programming" </div>
</ul>
JS
// NOTE: jQuery is required

var lastID = 0;

function updateSearch(slide) {
    var slideDuration = (slide === false) ? 0 : 300;

    // NOTE: "search-ticker.php" contains the PHP in this example
    $.post('search-ticker.php', {sinceID: lastID}, function(data) {
        var results = $.parseHTML(data.html) || [];

        for(var i = 0; i < results.length; i++) {
            var result = results[i];

            $('.search-ticker .heading').after(result);

            $(result).slideDown(slideDuration);
        }

        if($('.search-ticker li').length > 5)
            $('.search-ticker li:nth-child(n+7)').slideUp(slideDuration);

        lastID = data.sinceID;
    }, 'json');
}

$(function() {
    updateSearch(false);

    // update the list every 5 seconds
    setInterval(updateSearch, 5000);
})
PHP
require_once 'src/ultimate.twitter.feed.php';

$options = array(
    'request_type' => Twitter::RequestSearch,
    'q' => 'programming',
    'result_type' => 'recent',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'cache_life' => 5,
    'count' => 5
);

$twitter = new Twitter($options);

list($data, $response) = array($twitter->GetRequestData(), array('html' => ''));

foreach($data['statuses'] as $tweet) {
    if(bccomp($tweet['id_str'], $_POST['sinceID']) !== 1)
        continue;

    $response['html'] .= '<li style="display: none">
        <img src="'. $tweet['user']['profile_image_url'] .'" />
        <div class="content">
            <div class="user">
                <a href="https://www.twitter.com/'. $tweet['user']['screen_name'] .'">
                    <span class="username">'. $tweet['user']['name'] .'</span>
                    <span class="screenname">
                        <small>@</small>'. $tweet['user']['screen_name'] .'
                    </span>
                </a>
            </div>
            <div class="time">
                <a href="'. $tweet['twitter_link'] .'"> '. date('j M', strtotime($tweet['created_at'])) .' </a>
            </div>
            <div class="text"> '. $tweet['text'] .' </div>
            '. ($tweet['is_retweet'] ? '<div class="retweet"> Retweeted by '. $tweet['retweeter']['name'] .' </div>' : '').'
        </div>
    </li>';
}

$response['sinceID'] = $data['statuses'][0]['id_str'];

echo json_encode($response);
Multiple Screen Names
Toggle Source
CSS
.twitter-style {
    margin: 0;
    padding: 0;
    list-style-type: none;
    background: white;
    border: 1px solid #eeeeee;
    color: #333333;
    border-radius: 6px;
}

.twitter-style .heading {
    color: #333333;
    padding: 12px;
    height: 20px;
    font-size: 18px;
    font-weight: bold;
}

.twitter-style li {
    border-top: 1px solid #e8e8e8;
    padding: 9px 12px;
    position: relative;
    line-height: 18px;
}

.twitter-style li:hover {
    background: #f5f5f5;
}

.twitter-style li img {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 48px;
    height: 48px;
    border-radius: 5px;
}

.twitter-style li a {
    color: #0084B4;
    font-weight: normal;
}

.twitter-style li .content {
    position: relative;
    margin-left: 58px;
    min-height: 51px;
}

.twitter-style li .content .user .username {
    font-weight: bold;
    font-size: 14px;
    color: #333333;
}

.twitter-style li .content .user .screenname {
    font-size: 12px;
    color: #999999 !important;
}

.twitter-style li .content .user a {
    text-decoration: none;
    font-weight: normal !important;
}

.twitter-style li .content .user a:hover .username {
    text-decoration: underline;
}

.twitter-style li .content .user small {
    color: #bbbbbb;
    font-size: 12px;
}

.twitter-style li .content .time {
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 12px;
}

.twitter-style li .content .time a {
    text-decoration: none;
    font-weight: normal !important;
    color: #999999;
}

.twitter-style li .content .time a:hover {
    text-decoration: underline;
    color: #0084B4;
}

.twitter-style li .content .retweet {
    margin-top: 5px;
    padding-left: 20px;
    color: #999999;
    font-size: 12px;
    background: url(../Images/retweet.png) left center no-repeat;
}
PHP
function twitterStyle($tweet) {
    $timestamp = strtotime($tweet['created_at']);

    list($date, $year) = array(date('j M', $timestamp), date('y', $timestamp));

    if($year != date('y'))
        $date .= (' '. $year);

    echo '<li>
        <img src="', $tweet['user']['profile_image_url'] ,'" />
        <div class="content">
            <div class="user">
                <a href="https://www.twitter.com/', $tweet['user']['screen_name'] ,'">
                    <span class="username">', $tweet['user']['name'] ,'</span>
                    <span class="screenname">
                        <small>@</small>', $tweet['user']['screen_name'] ,'
                    </span>
                </a>
            </div>
            <div class="time">
                <a href="', $tweet['twitter_link'] ,'"> ', $date ,' </a>
            </div>
            <div class="text"> ', $tweet['text'] ,' </div>
            ', ($tweet['is_retweet'] ? '<div class="retweet"> Retweeted by '. $tweet['retweeter']['name'] .' </div>' : ''),'
        </div>
    </li>';
}

$options = array(
    'screen_name' => array('codecanyon', 'graphicriver', 'themforest', '3docean', 'audiojungle', 'activeden', 'photodune', 'videohive'),
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'html_before' => '<ul class="twitter-style"> <div class="heading"> Envato Marketplaces </div>',
);

$twitter = new Twitter($options);

$twitter->PrintFeed('twitterStyle');
Displaying Favorites
Toggle Source
CSS
.twitter-style {
    margin: 0;
    padding: 0;
    list-style-type: none;
    background: white;
    border: 1px solid #eeeeee;
    color: #333333;
    border-radius: 6px;
}

.twitter-style .heading {
    color: #333333;
    padding: 12px;
    height: 20px;
    font-size: 18px;
    font-weight: bold;
}

.twitter-style li {
    border-top: 1px solid #e8e8e8;
    padding: 9px 12px;
    position: relative;
    line-height: 18px;
}

.twitter-style li:hover {
    background: #f5f5f5;
}

.twitter-style li img {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 48px;
    height: 48px;
    border-radius: 5px;
}

.twitter-style li a {
    color: #0084B4;
    font-weight: normal;
}

.twitter-style li .content {
    position: relative;
    margin-left: 58px;
    min-height: 51px;
}

.twitter-style li .content .user .username {
    font-weight: bold;
    font-size: 14px;
    color: #333333;
}

.twitter-style li .content .user .screenname {
    font-size: 12px;
    color: #999999 !important;
}

.twitter-style li .content .user a {
    text-decoration: none;
    font-weight: normal !important;
}

.twitter-style li .content .user a:hover .username {
    text-decoration: underline;
}

.twitter-style li .content .user small {
    color: #bbbbbb;
    font-size: 12px;
}

.twitter-style li .content .time {
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 12px;
}

.twitter-style li .content .time a {
    text-decoration: none;
    font-weight: normal !important;
    color: #999999;
}

.twitter-style li .content .time a:hover {
    text-decoration: underline;
    color: #0084B4;
}

.twitter-style li .content .retweet {
    margin-top: 5px;
    padding-left: 20px;
    color: #999999;
    font-size: 12px;
    background: url(../Images/retweet.png) left center no-repeat;
}
PHP
function twitterStyle($tweet) {
    $timestamp = strtotime($tweet['created_at']);

    list($date, $year) = array(date('j M', $timestamp), date('y', $timestamp));

    if($year != date('y'))
        $date .= (' '. $year);

    echo '<li>
        <img src="', $tweet['user']['profile_image_url'] ,'" />
        <div class="content">
            <div class="user">
                <a href="https://www.twitter.com/', $tweet['user']['screen_name'] ,'">
                    <span class="username">', $tweet['user']['name'] ,'</span>
                    <span class="screenname">
                        <small>@</small>', $tweet['user']['screen_name'] ,'
                    </span>
                </a>
            </div>
            <div class="time">
                <a href="', $tweet['twitter_link'] ,'"> ', $date ,' </a>
            </div>
            <div class="text"> ', $tweet['text'] ,' </div>
        </div>
    </li>';
}

$options = array(
    'request_type' => Twitter::RequestFavorites,
    'screen_name' => 'envato',
    'consumer_key'  => '...',
    'consumer_secret' => '...',
    'user_token' => '...',
    'user_secret' => '...',
    'html_before' => '<ul class="twitter-style"> <div class="heading"> Envato\'s Recent Favorites </div>',
);

$twitter = new Twitter($options);

$twitter->PrintFeed('twitterStyle');