craft.feeds
This document is for a version of Craft CMS that is no longer supported. Please refer to the latest version →
You can capture RSS and Atom feeds using craft.feeds
.
# Methods
The following methods are available:
# getFeedItems( url, limit, offset, cacheDuration )
Returns the items in the feed located at the given URL.
Only the first argument is required (url
). If limit
is passed, the function will return no more than that many items. If offset
is passed, that many items will be skipped from the beginning of the feed. And if cacheDuration
is passed, the results will be cached for the given amount of time. (If no cacheDuration
is passed, Craft will default to the time specified by the cacheDuration config setting.)
# Item Properties
Each item will have the following properties:
authors
– An array of the item’s authors. Each element is a sub-array with the valuesname
,url
, andemail
.categories
– An array of the item’s categories. Each element is a sub-array with the valuesterm
,scheme
, andlabel
.content
– The item’s main content.contributors
– An array of author info. Each element is a sub-array with the valuesname
,url
, andemail
.date
– The item’s date.dateUpdated
– The item’s last updated date.permalink
– The item’s permalink URL.summary
– The item’s summary content.title
– The item’s title.
Here’s a basic example of what it all might look like:
{% set feedUrl = "http://feeds.feedburner.com/blogandtonic" %}
{% set limit = 10 %}
{% set items = craft.feeds.getFeedItems(feedUrl, limit) %}
{% for item in items %}
<article>
<h3><a href="{{ item.permalink }}">{{ item.title }}</a></h3>
<p class="author">{{ item.authors[0].name }}</p>
<p class="date">{{ item.date }}</p>
{{ item.summary }}
</article>
{% endfor %}