Creating an RSS Feed with Views

We get many requests from site builders that want to provide an RSS feed that lists content from their sites.  The RSS feed provides a list of links for designated content (most frequently news and events) to display on a browser or phone. People can subscribe so they can view the list that is updated automatically as content is added to the site.

Creating an RSS Feed with YaleSites can be done with a few adjustments to the News and Events pre-built features. For this example we will use the News Content Type and View.

News Content Type Adjustments

RSS format is very simple, displaying just a Title, description, author, and publication date. Most of the fields that you need for an RSS feed already exist in the News Content Type, but you will need to add the Path and Author fields in order to capture that information.

Creating the RSS Feed with Views

The Views Module provides RSS Feed as one of the display options. This makes it relatively easy to create an RSS feed for your site.  You just need to set the filters and fields based on the RSS format.

In the News View:

Be sure to apply theses changes to This display

  1. Choose Feed from the Display drop-down in the views interface.
    Choose Feed
  2. Click on Content

    and change that option to Fields

    You will be asked to override the fields, but first you need to adjust the fields in your list so that it includes only the fields that are part of an RSS Feed. Just click Cancel and you will return to that after your fields are adjusted. The Format section will look like this:
  3. Go to the Path Settings section in the middle panel of the View and enter a path i.e. rss-news
    Path Settings
  4. Go to the Fields section of your View.
  5. Delete the Image field.
  6. Click on the Title field.
    • Set display to settings to
       
    • Uncheck the Link this field to original content
    • Make sure Strip HTML is checked.
      Uncheck Strip HTML Tags
    • Click on the Description field.
    • Make sure Strip HTML is checked (see image above)
  7. Click on the Add button and add the Path field to link to the content.
    Choose the path field
    • Make sure Strip HTML is checked (see image above)
    • Uncheck label at top.

Creating the Date Format

The YaleSites News Feature comes with a date field, but the format needs to be adjusted. Because the RSS feeds uses the RFC 2822 date format, your date field needs to be formatted in order for it to be accepted. You can to create the format in the following way, then assign it to the View.

  1. Choose Configuration > Date and Time
  2. Click the Formats tab to add the Date format
  3. Choose r from the PHP Manual (click to enlarge)

    Type the lower case r in the Format string field and click Add format.
  4. Click Types to create a new type and assign the new format
  5. Give it the name RSS format and choose the new date format.
    Choose the Date format
  6. Go back to your view and assign the date format to the Date field. Click on the Date field and choose RSS format from the list.
  7. Format is better but still has HTML. GO into the view and strip the HTML tags (UNCHECK THE CHECK BOX SEEN BELOW).
    Uncheck Strip HTML Tags

Adding the Author Field

Each piece of content that is added to your site is stamped with an author, or the person who created the page. This information is part of the People Profile so it is not added directly to the News Content Type. Therefore in order to associate the Author field with the News Content Type, a Relationship must be created.

Creating the Relationship

  1. Click on the Advanced link in the far right panel of your Views interface.
  2. Locate the Relationships section and click on Add.
  3. Locate the Content:Author field, click on the check box, then scroll down and apply to This Display.Choose author as relationship

Adding the Author Field

Now that you have the relationship you can add the Author field in the Field section

  1. Click on Add in the Field Section
  2. Locate the User:Name field
    Author Field
  3. Click on the check box, then scroll down and apply to This Display.
  4. Uncheck the Link this field to its user check box.

Go back and Setup the RSS Field Mapping

  1. Click on Settings next to Field under FORMAT and map the following:
    • Title > Title
    • Link field > Content:Path
    • Description field > Content:Body
    • Creator field > (author) User:Name
    • Publication date field > Content: Date
    • GUID Settings > Content:Path GUID field – unique identifier – typically the path is unique so that’s a good one to use.
      Click to enlarge field mapping image.

Attaching an RSS Image to the News display

Once you have created the feed, you might want to attach an RSS icon to the main news listing so people can easily subscribe to it. This is relatively easy to do.

  1. In the middle pane of your Views Interface, click on None next to Attach to
    click on none
  2. Click on the checkboxes next to the pages you want to attach the RSS image. 
    attach feeds
  3. When you save the View, an RSS feed icons displays at the bottom of the news listing.

Additional RSS Feeds Based on Taxonomy Tags

You can also add additional filters through the Filter section of your Views interface or using Contextual Filters.

Helpful Hints

  • Always view the preview to make sure the RSS is displaying correctly.
  • If odd characters are showing up, enable Strip HTML tags in the Rewrite the Output section of the field configuration.
  • For even more control use the Views RSS Module.