More in this section

Forums / Developing with Sitefinity / Tag Cloud that spans multiple providers

Tag Cloud that spans multiple providers

2 posts, 0 answered
  1. HRC
    HRC avatar
    44 posts
    Registered:
    16 Mar 2009
    18 Mar 2010
    Link to this post
    So I understand that the tags and categories are specific to a provider (Blogs, News, etc.). 

    That is, if I tag a Blog Post with "Tag A" and I tag a News Release with "Tag A", in effect those are two different, independent tags that have nothing to do with each other.

    My requirement is to build a site-wide Tag Cloud / Tag List / Category List that spans the entire spectrum of content types (or Providers).  So whether it's a blog post, news release, event, generic content, or otherwise - the tags would roll up into one global Tag Cloud.  Then if the user clicks on "Tag A" within that Tag Cloud, they would be presented with a list of "stuff" matching that tag.

    If you think about it, it's a pretty reasonable request.  The end user should not have to figure out just what bucket of information she should be looking in.  They are just interested in *anything* tagged with "Tag A".

    I think I understand the difficulties in doing this, but I guess what I'm asking for is guidance as to whether or not it's even possible, or perhaps this is a feature of version 4.0 that I should wait for.

    Maybe this is some Frankenstein version of search and tag clouds?  Thoughts?

    Thanks in advance,

    Chris.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 Mar 2010
    Link to this post
    Hi iStudio,

    We will support this feature from Sitefinity 4.0. However you can achieve desired result in 3.x version as well.

    1. You need to create a custom control that inherits from ContentView. Then override CreateDataSource() method. Inside this method you need to create new instance of each provider you want to use (GenericContent, News,Events, Blogs) etc and call GetContent method to retrieve a list of filtered items. To filter each list you can use ContentFilterBuilder class instance inside CreateChildControls method

    ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", tag.TagName, ContentFilter.Condition.Equal,ContentFilter.JoinType.And));
    .

    sample code

    public class ContentViewCustomControl : ContentView
    {
        public ContentViewCustomControl()
        {
     
        }
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Generic_Content/ContentViewItemList.ascx";
            }
     
        }
     
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            ListContainer.RepeaterControl.DataSource = CreateDataSource();
            ListContainer.RepeaterControl.ItemDataBound += new RepeaterItemEventHandler(RepeaterControl_ItemDataBound);
            ListContainer.DataBind();
            
        }
     
        void RepeaterControl_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                IContent conten = e.Item.DataItem as IContent;
            }
        }
     
        protected override IList CreateDataSource()
        {
            IList<IContent> mergedList = new List<IContent>();
            contentManager = new ContentManager("Generic_Content");
            contentManager = new ContentManager("News");
            // you can perform filtering here - this will be better for the performace
            // the method has 21 overloads that you can use.
            //if you do not filter the list here - do it inside CreateChildControls
            // by using ContentFilterBuilder
            IList contentList = contentManager.GetContent();
     
            // here populate mergedList and return it.
     
     
            return mergedList;
        }
     
     
        private ContentManager contentManager;
       
     
    }
     

    2. Configure the CategoriesTree control to use metakeys so you can retrieve the category name from the QueryString. By default the control uses ID of the category/tag which is unique for each ICategory object.

    • Drop your custom ContentView control and under Properties Tab >> QuerystringKeys, set CategoryKey and CategoryKeyType to Name ( the same applies for tags).
    • Open CategoriesTree/TagsList control and under Behavior tab set CategoryContentUrl, CategoryKey and CategoryKeyType to Name

    Best wishes,
    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