Displaying RSS Feeds From External Sites
The Drupal core module "Aggregator" can help sites fetch content from other sites and display that content on any section of a page, such as a News and Events page. For this example we are looking at adding a feed from UC Santa Barbara's The Current to a UCSB Web Theme site, currently running Drupal 9. This will also work for Drupal 7, 8 and 10.
Enable the Aggregator module
Since this module is a part of Drupal core, it is available on any Drupal site. Go to Extend > select Aggregator > Install
Grab the Source URL
Configure the source URL to be featured on your site. In this example, I want to use a feed from The Current that features the latest articles from the Arts & Photography category. To get the source URL, the bottom of the page features an RSS icon and a link. Once the link is copied, paste it into the Aggregator module's Configuration page. Go to Configuration > Aggregator > Add Feed and enter the URL and give the feed a name.
Update Items to Start Fetching Content
Now that the site is connected to the RSS Feed from The Current, click 'update items' for your feed to retrieve the RSS feed's articles and parse the items by going to Configuration > Web Services > Aggregator > Edit dropdown > Update Items
Create a View that will show 'Aggregator items'
With the setup complete, we could stop here and load in the new Feed as a block and place that block in a region (or page) on our site. But we want some refinement with the output, so let's create a View and then we can place the View into a section of our News landing page. Go to Structure > Views > Add View
Manage Display of Each Feed Item
This is where you can tweak the output of the feed items. Out of the box, there may be too much information presented so the display of stories can be refined here. To make a change, go to Configuration > Aggregator > Manage Display.
For this example, all the fields have been removed except for the one labeled Items:
Set Permissions
Out of the box, only authenticated users can see the feed. We need to allow for Anonymous Users to see this content too. Go to People > Permissions > under Aggregator - Views News Feeds > select Anonymous User > Save
Final Look
This example is using UCSB Web Theme site, so we are going to place our View inside of a column on a page, with a smaller column used on the left to give our RSS feed some source context. Now that we have everything in place, our website will automatically check The Current every hour to fetch new content. Any new stories will get populated at the top. With this in mind, we never have to touch this area of our site as this is now dynamically populating for us. Yay!
Extras
- Adjust settings for the feed items like the number of items to show, or which HTML tags are allowed by going to Configuration > Aggregator > Settings
- Read more about the module, including an overview of the setup
- There is an opportunity to have our website turn each story into a node (Drupal's term for page) on our site, rather than a feed. This provides a lot more flexibility with how the articles are displayed on your site, but it also requires another module, called Feeds.
- As of this writing, the module looks to be moving away from being a Drupal Core module and will move to being a contribution module. The configuration and setup will be the same, but the need to install the module may be needed going forward at the end of 2023 or beginning of 2024.