Fun with RSS using Aggregator Module

The Drupal Aggregator module is somewhat misnamed. It certainly does aggregate RSS/RDF/Atom feeds, but at the core it's a feed reader. I haven't needed to aggregate multiple feeds together, but recently being able to retrieve and display individual feeds has allowed me to add some cool sidebars to my Digital Doodles website.

By simply turning on the Aggregator module, which is a core module so no installation required, and adding the RSS feed from Group42 and another site I contribute to I can retrieve the post information back to Digital Doodles. I've set up blocks to show a list of recent postings in case people visiting Digital Doodles might be interested in stuff I done elsewhere.

The weakness of the Aggregator module is it's display ability. For example, although it automatically creates a sidebar block for each feed you define there's no ability to add anything except a title. The power of Drupal gives themers and programmers a number of options around this.

I've implemented the Digital Doodle sidebar blocks as custom block with PHP. I found the following PHP snippet on the Drupal site:

<pre>
&lt;div&gt;Some text describing the feed&lt;/div&gt;
&lt;?php
  $result = db_query_range('SELECT * FROM {aggregator_item}
                            WHERE fid = %d
                            ORDER BY timestamp DESC, iid DESC', 2, 0, 5);
  $items = array();
  while ($item = db_fetch_object($result)) {
    $items[] = theme('aggregator_block_item', $item);
  }
  // Only display the block if there are items to show.
  if (count($items) > 0) {
    $output = theme('item_list', $items);
  }
  print $output;
?&gt;
</pre>

The only tricky part is getting the feed id, which in the example above is 2. This is actually pretty simple, it's in the URL of the feed.

It's also possible to custom format blocks and feeds by overriding theme functions in template.php. In my case, creating a custom block was easier.

Not a killer cool feature in my case, but a petite cool one. Especially when you consider how easy it is.

Comments

To think I actually UNDERSTAND what you're talking about blows my mind. Now if I could only grasp the intricacies of it all...