How to Add Twitter to Your Drupal Site
Update: This tutorial was written before there was a Twitter module. You might want to take a look at the Twitter module first: http://drupal.org/project/twitter.
One of the best communication tools on the Internet today for both individuals and businesses is Twitter.com. Twitter is a short form communication tool that allows you to post a message of 140 characters or less. As a member of Twitter, I can follow other users and view their updates. How does this benefit individuals or businesses? A lot of very interesting individuals are on Twitter. One way for an individual to benefit from Twitter is to use the service as a way to keep their followers updated on the latest news about themselves. You can point followers to recent blog posts or even to your latest project. Another example is Dell. Dell uses the service to keep their customers updated on the latest discounts for their products. Twitter is a great way for both individuals and businesses to leverage their brand equity.
This article will explain how to easily add your Twitter updates to your Drupal site. We will add the code provided by Twitter to a Drupal block, and then use CSS to style the block to fit our site. Our finished product will look like this:











</ul> </div> and </script> tags? They do not belong in the code and we need to fix this before we click “Save block.” Scroll back up to “Block body.” Copy just this portion of the HTML/JavaScript code:
<script type="text/javascript" src="http://twitter.com/javascripts /blogger.js"></script>,<script type="text/javascript" src="http://twitter.com /statuses/user_timeline /Anarchtica.json?callback=twitterCallback2& amp;count=5"></script>
<h2> and </h2> tags to look like this:
<div id="twitter_div"><h2 class="twitter-title">twitter</h2><ul id="twitter_update_list"></ul></div>
<h2> and </h2> tags is the actual heading for our Twitter block. You can change this text fit your style.
Now you can click “Save block.”
After you click “Save block,” you will be taken to the build block page. Hover your mouse over the cross to the left of the block that says Twitter and move it into the region you would you would like the block to display in. I have placed my block in the right sidebar region:


<body> tag resides, so we will paste the code there.
You can find the page.tpl.php page in the same folder as your theme. So open up your favorite FTP client and navigate to your theme’s folder. For example, if you are using the Garland theme, navigate to /themes/garland and you will see page.tpl.php. I am using the Zen theme that I have modified to be a sub-theme. Therefore, my page.tpl.php page was located in the main Zen theme directory. Since I wanted to modify the page.tpl.php page, I had to copy that file and place it into my sub-theme directory. I could then modify the file located in the sub-theme directory, and it would take precedence over the page.tpl.php page located in the Zen theme directory. Edit the page.tpl.php page by copying the code you saved earlier and pasting it right above the </body> tag so that it looks similar to this (remember to delete the comma that is located between the two <script>,</script> tags):
<script> and </script> tags is what we pasted into the page.tpl.php page. Remember to paste in your specific code and to not copy and paste my code since this has my specific Twitter information. Save this change and now go back to your site. Your Twitter block should now look similar to this:

div#twitter_div { font-size: 12px; /* use this to change the font size of the Twitter updates */ font-weight: bold; /* I made the Twitter updates font bold to make it easier to read */ border-style: solid; /* makes the border around the Twitter block solid */ border-width: 2px; /* sets the width of the border around the Twitter block */ border-color: #C5C295; /* sets the color of the border around the Twitter block */ text-align: justify; /* makes the Twitter updates text justified */ background-color: #D7D39A; /* sets the background color of the Twitter block */ } #twitter_div ul { margin: 0px 10px 0px 10px; /* positions the Twitter update text 10 pixels from the right and 10 pixels from the bottom. This makes the text line up properly in the Twitter block. */ padding: 0px 0px 10px 0px; /* sets the padding of the Twitter update text to 10 pixels from the bottom */ } #twitter_update_list li { margin: 10px 0px 0px 0px; /* separates the Twitter updates with a 10 pixel margin at the top between each of the updates */ padding: 0px 0px 10px 0px; /* gives a 10 pixel padding between each of the Twitter updates on the bottom */ list-style-type: none; /* gets rid of the bullet point next to each of the Twitter updates */ border-bottom: 2px solid #C5C295; /* separates each of the Twitter updates with a 2 pixel border at the bottom and gives it a color */ color: #555555; /* sets the font color for the Twitter updates */ } .twitter-title { font-size: 20px; /* sets the Twitter title font to 20 pixels */ font-weight: normal; /* sets the title font weight to normal */ color: #444444; /* sets the title font color */ text-align: center; /* centers the title within the Twitter block */ background-color: #7D9C1F; /* sets the green background color for the title */ }
