Display Latest Tweets From A Twitter Account Using HTML

Introduction

 
Friends,
 
Social media is one of the most engaging mediums of communication today and every blogger wants to display tweets from his/her specific account on the website. This article shows how to briefly display your latest tweets on your website without knowledge of any programming language. You can just copy and paste the code and start displaying your tweets immediately on your website. You can directly copy and paste the code into Wordpress widgets or a plugin or a custom-built website or at any position of your website you want it to.
 
Let's write the HTML markup
  1. <div id="twitter">  
  2.     <ul id="twitter_update_list">  
  3.     </ul>  
  4.      </div>  
  5. <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>  
  6. <script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=niteshluharuka&include_rts=true&count=10&callback=twitterCallback2"></script> 
In the code above, in line 3 you notice the parameter "screen_name=niteshluharuka". You will need to change this to your desired twitter account username from where you want to display the tweets from. So, if your twitter handle is "mytwitterhandle", then replace "screen_name=niteshluharuka" with "screen_name=mytwitterhandle" in line 3.
 
You are done and if you want the displayed tweets to use the default stylesheet of your website, copy the code above and paste at your desired position. In case you want to do some custom styling, continue reading.
 
For styling the tweets displayed, let's add some styles to the HTML markup. Add the following section in the head section of your website:
  1. <style type="text/css">< #twitter {  
  2.   width: 310px;  
  3.   border: 2px solid #CCC;  
  4.   font-family: Tahoma;  
  5.   font-size: 13px;  
  6.   height: 300px;  
  7.   overflow: auto;  
  8.   margin: 10px 0px;  
  9. }  
  10.  
  11. #twitter ul {  
  12.   list-style: none;  
  13.   margin: 0;  
  14.   padding: 0;  
  15. }  
  16.  
  17. #twitter ul li {  
  18.   border-bottom: 1px dotted #CCC;  
  19.   padding: 10px 5px;  
  20.   margin: 0px;  
  21.   line-height: 22px;  
  22. }  
  23.  
  24. #twitter ul li a {  
  25.   font: normal 14px Tahoma;  
  26.   color: #004080;  
  27. }  
  28.  
  29. #twitter ul li a:hover {  
  30.   color: #CC0000;  
  31. }  
  32. </style>  
  33. </style> 
If you want to add a "Follow" button to your twitter account then add the following line after the markup:
  1. <iframe style="height: 20px; text-align: right;" src="http://platform.twitter.com/widgets/follow_button.html?screen_name=niteshluharuka&show_count=false&lang=en"  
  2.    height="240" width="320" frameborder="0" scrolling="no"></iframe>  
  3. The following is the complete code:  
  4. <style type="text/css">  
  5.    #twitter  
  6.    {  
  7.    width: 310px;  
  8.    border: 2px solid #CCC;  
  9.    font-family: Tahoma;  
  10.    font-size: 13px;  
  11.    height: 300px;  
  12.    overflow: auto;  
  13.    margin: 10px 0px;  
  14.    }  
  15.    #twitter ul  
  16.    {  
  17.    list-style: none;  
  18.    margin: 0;  
  19.    padding: 0;  
  20.    }  
  21.    #twitter ul li  
  22.    {  
  23.    border-bottom: 1px dotted #CCC;  
  24.    padding: 10px 5px;  
  25.    margin: 0px;  
  26.    line-height: 22px;  
  27.    }  
  28.    #twitter ul li a  
  29.    {  
  30.    font: normal 14px Tahoma;  
  31.    color: #004080;  
  32.    }  
  33.    #twitter ul li a:hover  
  34.    {  
  35.    color: #CC0000;  
  36.    }  
  37. </style>  
  38. <div id="twitter">  
  39.    <ul id="twitter_update_list">  
  40.    </ul>  
  41. </div>  
  42. <script src="http://twitter.com/javascripts/blogger.js" type="text/javascript"></script>  
  43. <script src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=niteshluharuka&include_rts=true&count=10&callback=twitterCallback2"  
  44.    type="text/javascript"></script>  
  45. <iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/follow_button.html?screen_name=niteshluharuka&show_count=false&lang=en"  
  46.    style="height: 20px; text-align: right;"></iframe> 
The following is the output of the code above:
 
twitter.jpg
 
So, copy & paste and let your visitors see your tweets immediately on your website.
 
Let me know if you encounter any issues implementing this.


Rebin Infotech
Think. Innovate. Grow.