loading...
Epicosity

Displaying an RSS Feed in CraftCMS

egf profile image Elise Gaetz Ferguson Originally published at Medium on ・2 min read

CraftCMS doesn’t appear to have a built-in way to display RSS feeds and more often than not, clients want to display their recent or related blog posts on their main website.

The first thing we did to tackle this challenge was install the Craft RSS plugin by Guilty AS.

The GitHub page for the plugin has an example of how to display the RSS feed in your templates and it’s pretty straight forward.

Sample code from Guilt AS

Just plug in your RSS Feed URL and off you go.

Naturally you’ll want to arrange the results of the feed in a way that best matches your site’s design.

You are might want to limit the number of posts you are showing. To do that we set a counter = 0 at the beginning of the block (line 2 below). Then before each “for post in blogFeed.item” loop we check if the counter is less than the number of posts we want to show (line 9). Right before the end of the loop then increment the counter with a +1 (line 17).

Code example with counter

If you want to make this a little more flexible you could create a field in Craft to take in the URL of the blog feed, either per entry or as a global.

If you really want to get fancy you could create several different type of display options (card, list, etc) and let the user choose how they want to display the information.


Posted on by:

Epicosity

We’re a Sioux Falls-based global marketing agency, blending the traditional with a strong digital footprint. We’re storytellers with a digital edge.

Discussion

markdown guide