I’m writing this blog post for the Austin Drupal Newbies February Meetup to go along with my presentation about Drupal and Twitter.
Drupal sites can display the most recent tweets for a Twitter @username with the twitter_pull module for Drupal 6 and 7. The twitter_pull module is one of many Twitter-related modules for Drupal – a quick search on drupal.org revealed 151 matches for Twitter modules.
Twitter_pull solves one problem, and one problem only – retrieving recent tweets and displaying them in Drupal.
The module was written for developers to use with PHP – it isn’t configurable from the Admin menu like most other modules, at least in the most recent Drupal 6 release. This means you will have to do a few extra steps to get the twitter_pull module running on a stock Drupal 6 installation.
I’m going to give directions on how to show your recent tweets in a block in the right hand sidebar of a stock, out of the box Drupal 6.20 installation on a UNIX host that you have shell access to – for instance, a VPS or a shared host like PHPWebhosting. You can also install the twitter_pull module using drush or anything else you’re already comfortable with.
Downloading and Installing the Twitter Pull Module
cd drupal
cd sites/all mkdir modules cd modules
wget http://ftp.drupal.org/files/projects/twitter_pull-6.x-1.2.tar.gz
tar fxzv twitter_pull-6.x-1.2.tar.gz
Enabling the Twitter Pull and PHP Filter Modules
http://www.yourserver.com/admin/build/modules
The two modules we need to enable are “PHP Filter” and “Twitter Pull”. Twitter Pull is the module we just downloaded, so it makes sense that we need to enable it.
Why do we need to enable “PHP Filter”? The reason is that the Twitter Pull module requires a small amount of PHP code to make it work. We are going to put that PHP code into a Drupal block. A fresh, clean, new Drupal 6 installation doesn’t let you use PHP code in a block – you will need to enable the “PHP Filter” module that comes with Drupal 6 for this to work.
After checking the boxes next to “PHP Filter” and “Twitter Pull”, click the “Save Configuration” button at the bottom of the modules page.
Creating the Recent Tweets Block
http://www.yourserver.com/admin/build/block
Now, add a block from that page
http://www.yourserver.com/admin/build/block/add
<?php if (function_exists('twitter_pull_render')) { print twitter_pull_render('@jefflinwood', '', 10); } ?>
Now, change @jefflinwood to your Twitter username – @racetothealtar, for instance.
To make Drupal execute the PHP code in your block, you need to set the Input Format on the block to be PHP Code. If you didn’t enable the PHP Filter module earlier, you will not see this option here.
The defaults for the rest of the block should be okay. Save the block. Your block is now configured and ready to display.
Displaying the Block
Under disabled, change the drop-down for Recent Tweets from <none> to Right Sidebar. Now click the Save Blocks button – you should see the Recent Tweets in your right sidebar! Go to your front page, and they should be there as well.
One reply on “Displaying Recent Tweets in Drupal 6 with twitter_pull”
Thank you. You were the first person to be able to competently explain this. You should win the nobel prize for this article.
I just spent 2 hours trying to modify that stupid twitter pull, and here I needed to make my own.
bless you!