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

The first step is to login and change directories on your host to your Drupal directory.

cd drupal
Next, create your sites/all/modules directory if it doesn’t already exist. Change your working directory to the modules directory.
 cd sites/all
 mkdir modules
 cd modules
Once you are in the modules directory, use the wget command to download the Drupal 6 version of Twitter_pull into your modules.
wget http://ftp.drupal.org/files/projects/twitter_pull-6.x-1.2.tar.gz
Now, uncompress the twitter_pull module
tar fxzv twitter_pull-6.x-1.2.tar.gz
We can log out of the Unix shell now. With Drupal 7, it’s much easier to install modules through the administration interface.

Enabling the Twitter Pull and PHP Filter Modules

The next step is to go to our Drupal Administration modules page. Login as the administrator to your Drupal site, and go to Site Building->Modules. We need to enable two 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

Now, we need to configure a Drupal block to display our recent Tweets. Start at the Blocks Administration page:

http://www.yourserver.com/admin/build/block

Now, add a block from that page


http://www.yourserver.com/admin/build/block/add
Set the block description to Recent Tweets, and the block title to Recent Tweets as well. Next, inside the block body, we will have to use some PHP code. Don’t worry if you aren’t familiar with PHP, this is a great way to get your feet wet. We only have to change one thing to customize this for your site! Copy and paste the following into your block body.
<?php if (function_exists('twitter_pull_render')) { print twitter_pull_render('@jefflinwood', '', 10); } ?>
What we are doing in the above PHP code is first, checking to see if the Twitter Pull module is enabled. If it is, we are making a call to the twitter_pull_render PHP method from the Twitter Pull module with three arguments: the Twitter search, the title to use, and the number of Tweets to show. In our case, we are using @jefflinwood as the Twitter search term, no title, as the title is provided by the block, and we are going to show up to 10 recent Tweets.

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 comment 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!

Comments are closed.