Skip to main content

Example: syndicate children of multiple items

You can implement a custom RSS feed based on the following example that syndicates the children of all of the items selected in the field named Sources in the feed definition item.

In the Visual Studio Web application project, compile a class based on the following example:

namespace Sitecore.Sharedsource.Syndication
{
    public class SelectionFeed : Sitecore.Syndication.PublicFeed
    {
        public override System.Collections.Generic.IEnumerable<Sitecore.Data.Items.Item> GetSourceItem()
        {
            Sitecore.Data.Fields.MultilistField entries = this.FeedItem.Fields["Sources"];

            if (entries == null || entries.Count < 1)
            {
                return new Sitecore.Data.Items.Item[0];
            }

            Sitecore.Collections.ItemList list = new Sitecore.Collections.ItemList();

            foreach (Sitecore.Data.Items.Item parent in entries.GetItems())
            {
                foreach (Sitecore.Data.Items.Item child in parent.Children)
                {
                    if (Sitecore.Syndication.FeedUtil.IsConfiguredForFeed(child))
                    {
                        list.Add(child);
                    }
                }

            }

            if (list.Count < 1) {
                return new Sitecore.Data.Items.Item[0];
            }

            list.Sort(new Sitecore.Data.Comparers.UpdatedComparer());

            return list.ToArray();
        }
    }
}

In the Template Manager or the Content Editor, in the System/Feeds/RSS Feed data template, in the Extensibility section, add a Treelist field named Sources, and set the Source property of this field to the /sitecore/content item.

In the Content Editor, in the feed definition item, in the Extensibility section, in the Type field, enter the signature of the class: Sitecore.Sharedsource.Syndication.MultiParentFeed, Assembly

In the Content Editor, in the feed definition item, in the Extensibility section, in the Sources field, select items with children to syndicate.