Show latest tweet on magento

Creat file get_tweet.phtml with code below and place to app/design/frontend/default

/your_template_name/template/callouts

 

<?php
function getTimeAgo($time){
$tweetdate = $time;
$tweet = $tweettag["content"];
$timedate = explode(" ",$tweetdate);
$date = $timedate[0];
$time = substr($timedate[1],0, -1);
$tweettime = (strtotime($date." ".$time))+3600; // This is the value of the time difference - UK + 1 hours (3600 seconds)
$nowtime = time();
$timeago = ($nowtime-$tweettime);
$thehours = floor($timeago/3600);
$theminutes = floor($timeago/60);
$thedays = floor($timeago/86400);
/********************* Checking the times and returning correct value */
if($theminutes < 60){
if($theminutes < 1){
$timemessage =  "Less than 1 minute ago";
} else if($theminutes == 1) {
$timemessage = $theminutes." minute ago.";
} else {
$timemessage = $theminutes." minutes ago.";
}
} else if($theminutes > 60 && $thedays < 1){
if($thehours == 1){
$timemessage = $thehours." hour ago.";
} else {
$timemessage = $thehours." hours ago.";
}
} else {
if($thedays == 1){
$timemessage = $thedays." day ago.";
} else {
$timemessage = $thedays." days ago.";
}
}
return $timemessage;
}

?>
<ul>
<?php
$channel = new Zend_Feed_Rss('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=awarenessstraps'); // get from your twitter account (please changes with your acc)
$i = 0;
foreach ($channel as $item):
if ($i<1){ // limit to 3 ?>
<?php
$date = $item->pubDate('j F Y');
$date = substr($date, 0, -15);
$text = $item->description;
utf8_encode($text);
$timemessage = strtotime($item->pubDate());
$timemessage = date("Y-m-d H:i:s",$timemessage);
?>
<li><?php echo $item->title; ?><br/>
<a href="<?php echo $item->link; ?>" title="<?php echo $item->title; ?>">Read Tweet &raquo;</a>
<span><?php echo getTimeAgo($timemessage); ?></span></li>
<?php
} // end the loop
$i++;
endforeach;
?>
</ul>
<a href="http://twitter.com/AwarenessStraps" target="_blank" title="Awareness Straps on Twitter">Follow us</a> <!--(please changes with your acc)-->

 

in your Blog please call

<div class="twitter_menu">{{block type="core/template" name="latest.tweet" as="get_tweet" template="callouts/get_tweet.phtml"}}</div>

Goodluck

Be Sociable, Share!

Leave a comment