View Plugin:FeedGrab

Introduction

The FeedGrab plugin allows you to insert the contents of RSS or ATOM feeds into Expression Engine weblogs.

Why?

The FeedGrab plugin, as well as allowing you to keep your own copy of the data in your own database, provides you with the ability to use all of Expression Engine’s nifty weblog features, such as calendar-based archives, the facility to randomly display items, search tools and the option of relating this external data with your own weblogs entries via EE’s related field feature.

With the data stored in a weblog you have the option of displaying the information however you like, either combined with other weblog data or on its own.

A look at the feed

The RSS feed I will be using is from mag.nolia.com and is a list of my most recently saved bookmarks. From the site I find its URL:

http://ma.gnolia.com/rss/lite/people/ajweaver

Loading this file in the browser and viewing its source shows its structure - the bits I’m interested in is between the <item> tags

    <item>
      <title>Compose to a Vertical Rhythm</title>
      <author>ajweaver</author>

      <description type="html"><p>Leading (line-height) a forgotten element of web typography.</p>
</description>
      <pubDate>2006-12-12T13:41:14-08:00</pubDate>
      <link>http://24ways.org/2006/compose-to-a-vertical-rhythm</link>

      <guid>http://ma.gnolia.com/people/ajweaver/bookmarks/mijolisc</guid>
      <category domain="http://ma.gnolia.com/tags">typography</category>
    </item>

For the purpose of this tutorial I want the title, description and link

Create a new weblog

Before creating the weblog I usually set up the custom fields

Create a new weblog field group and add 2 new fields for description (make it a textarea) and link (a text input). I’ll call these magnolia_body and magnolia_url (Note, a weblog always has a title field by default so we’ll use that for the title field)

Create a weblog called magnolia and assign the custom fields group to it.

Tip: Edit the preferences for this weblog ( Weblog Administration > Weblog Management > Edit Preferences) and in Weblog Posting Preferences set Automatically turn URLs and email addresses into links? to No.

From the Weblog Management page make a note of the weblog’s id.

Create template

We’ll create a template to view the results (you might want to manually enter some test data to check this).

Create a new template group. It should have an index template automatically into which add:

{exp:weblog:entries
    weblog="events" orderby="date"
    limit="10" show_future_entries="yes"}

<h4><a href="{magnolia_url}">{title}</a></h4>

<p>{magnolia_body}</p>

{/exp:weblog:entries} 


Set up plugin

Create another template called go and add the call the plugin:


{exp:feedgrab url="http://ma.gnolia.com/rss/lite/people/ajweaver" 
                          weblog="WEBLOG_ID" 
                          title="title"
                          date="pubDate"
                          use="link|description" 
                          fields="magnolia_url|magnolia_body" }

Replace WEBLOG_ID with the value you made a note of earlier.

The title="title” line tells the plugin to use the feed’s title as the weblog entry’s title, and date="pubDate” tells it to use the feed’s pubDate field as the weblog entry’s publish date.

The use="link|description” fields="magnolia_url|magnolia_body” section tells the plugin to put link into magnolia_url and description into magnolia_body.

To call the plugin, simply go to http://www.yoursite.com/index.php/feedgrab/go

This should add all the new RSS entries into your new weblog. Subsequent calls will only add new entries.

Parameters

url=

url="http://www.path.to/feed.rss”

The url of the feed to import

weblog=

weblog="1”

The id of the weblog to import entries into

author=

author="1”

The id of the author to associate with the imported entries

title=

title="title”

The feed element to use as the entry’s title

date=

date="dc:date”

The feed element to use as the entry’s publish date

use=

use="link|description”

A ‘pipe’ delimited list of fields from the RSS feed that you want to import

fields=

fields="magnolia_url|magnolia_body”

The (custom) fields that you want the use= fields inserted into.

The number of fields must match the number in the use= parameter.

category=

category="2”

or

category="flickr”

The id or name of the category to put entries in by default.

More on Categories.

refresh=

refresh="60”

How long to cache the feed for (default 60 minutes)

category_field=

category_field="categories”

The feed element that contains the category (or list of categories) to add the entry to

More on Categories.

category_delimiter=

category_delimiter="SPACE”

The delimiter between categories in the category_field element. Use the value “SPACE” for a space delimiter.

category_group=

category_group="2”

Categories that do not exist are created automatically. This parameter sets the id of the category group to create new categories in.

unique=

unique="guid”

The unique field determines which fields are checked to see if the current feed element ahas already been imported. Many feeds have a guid element which identifies a unique item, but you can also define your own combinations to check, eg,

unique="title,date”

will not import any items with the same title and date as an existing element in the selected weblog.

Note, the field names are the fields set up within your own weblog (ie, title, date, and any custom fields) not the names of the fields in the feed.

Additional links

Plugin: FeedGrab | ExpressionEngine Forum

Feedrab Tutorial on brandnewbox.co.uk