+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add category element to RSS output?

Add category element to RSS output?

2 posts, 0 answered
  1. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    29 Dec 2010
    Link to this post
    I am trying to include the category element in RSS feeds. So far the RSS XML only includes just these elements by default:

    <item>
      <title>News Item 100</title>
      <description>This is a test post</description>
      <author>Jim Jones</author>
      <guid isPermaLink="false">e9e0ceb9-fd7d-4c1d-9a85-26cfec6d2bad</guid>
      <pubDate>Tue, 20 Jul 2010 04:00:00 GMT</pubDate>
    </item>

    Is there anything in the web.config I can do to tell the RSS provider to include the category element? Such as in this section:

    <rssProviders>
        <clear/>
        <add name="Blogs" type="Telerik.Blogs.RssProvider, Telerik.Blogs" visible="True" applicationName="/Blogs" rssFieldAuthor="Author" rssFieldTitle="Title" rssFieldPubDate="Publication_Date"/>
    </rssProviders>

    Otherwise, would populating the property "Telerik.Rss.RssItem.Categories" work? I think I would just have to override the "SetGeneralProps" method in the RssChannelProvider class. Worse case would be touching the RssWriter if none of the above works (not sure where this is though). Any ideas or suggestions?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Dec 2010
    Link to this post
    Hello bemara57,

    There is not a web.config attribute that you can use and Categories property does not return ICategory object. The meaning here is different

    The rss engine displays data from IContent items and actually only the fields you have pasted.  You can inject the category text/link as a description of the rss, but this will not appear as a separate section.

    sample

    Copy Code
    public class ExtendedRssChanelProvider : Telerik.News.Rss.RssChannelProvider
    {
        public override string ContentItemKey
        {
            get
            {
                return ContentManager.ContentITemKey;
            }
        }
      
        public override string ContentProviderKey
        {
            get
            {
                return NewsManager.NewsProviderKey;
            }
        }
      
        public override string Name
        {
            get
            {
                return"CustomRssProvider";
            }
        }
      
        public override IList<Telerik.Rss.RssItem> GetRssItems(System.Collections.Specialized.NameValueCollection query)
        {
            var newList = newList<Telerik.Rss.RssItem>();
            var items = base.GetRssItems(query).Cast<Telerik.Rss.RssItem>().Take(20);
            foreach(Telerik.Rss.RssItem i initems)
            {
               i.Description = i.Description + "here add categories data or text you wan to see"
            }
            return newList;
        }
       
    }

    You can implement this logic in RssChannelProvider  or inherit from one of the built-in Rss providers as  my code above shows. Then you need to register your provider in the web.config

    Copy Code
    <channelProviders>
                <clear />
        <add name="Custom Rss Provider" type="ExtendedRssChanelProvider, App_Code" settingsControl="ExtendedRssSettignsControl, App_Code" viewSettingsControl="ExtendedRssViewControl, App_Code" description="extended RSS provide"></add>
        <add name="Page Rss Provider" type="Telerik.Cms.Web.RssChannelProvider, Telerik.Cms" settingsControl="Telerik.Cms.Web.UI.RssSettingsControl, Telerik.Cms" viewSettingsControl="Telerik.Cms.Web.UI.RssViewSettingsControl, Telerik.Cms" description="Provides RSS for CMS pages" />
            </channelProviders>


    You can  override GetContentData method of the RssHttpHandler and replace the default handler with the custom one inside your web.config file( <handlers> or <httpHandlers> depending on IIS version and mode you use) . The RssFeed uses  RssFeedInfo object which is used by the RssHttpHandler. This object has the following properties

    • Url
    • Name
    • Description
    • Version
    • ChannelUrl
    as you can see there is no property which gets the IContent and associated with it Category.
      Another option is implementing a custom object and method similar to GetRssItems and then use this object in GetContentData to write the xml of your rss.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered