Example: syndication entry categories

You can use the RSS format to associate multiple topic categories with each syndication entry. You can manage a list of categories as a folder containing category definition items.

You can add a selection field to each of the data templates for syndicated items to allow the CMS user to select any number of category definition items. You can include the categories in each syndication entry by populating the System.ServiceModel.Syndication.SyndicationItem.Categories list with the names of the category definition items.

You can implement a custom feed based on the following example that includes categories for syndication entries. In the Visual Studio Web application project, add a class based on the following example:

namespace Sitecore.Sharedsource.Syndication {

	using System.ServiceModel.Syndication;

	public class CategorizedFeed: Sitecore.Syndication.PublicFeed

	{
		protected override SyndicationItem RenderItem(Sitecore.Data.Items.Item item) {
			Sitecore.Diagnostics.Assert.ArgumentNotNull(item, "item");
			SyndicationItem entry = base.RenderItem(item);
			Sitecore.Data.Fields.MultilistField entries = item.Fields["Categories"];
			if (entries != null) {
				foreach(Sitecore.Data.Items.Item category in entries.GetItems()) {
					if (category != null) {
						entry.Categories.Add(new SyndicationCategory(category.Name));
					}
				}
			}
			return entry;
		}
	}
}

In the Content Editor, in the feed definition item, in the Extensibility section, in the Type field, enter the signature of the .NET type, such as the following:

Sitecore.Sharedsource.Syndication.CategorizedFeed, Assembly

In the Content Editor, create a folder containing category definition items.

In the Template Manager or the Content Editor, in the data template(s) used for syndication entries, add a selection field named Categories, and then set the Source property of the Categories field to the folder containing category definition items that you created in the previous step.

In the Content Editor, in the syndication entries, in the Categories field, select relevant categories.

Tip

Create a data template containing the Categories field, and add that data template as a base template for templates that support syndication.