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

Forums / Developing with Sitefinity / Filtering Tags for specific blogs in a Tag Cloud?

Filtering Tags for specific blogs in a Tag Cloud?

7 posts, 0 answered
  1. Jayakrishna
    Jayakrishna avatar
    5 posts
    Registered:
    25 Mar 2009
    17 Dec 2009
    Link to this post
    hi,

    I have 5 blogs in my website and i want to show all the blogs separately on different pages.
    When i use the Tags List control on the page, it is showing all the tags from all the blogs.
    But my requirement is, i want only Tags related to particular blog.

    Is this functionality available as inbuilt?
    or do i need to implement this functionality?

    I am using Sitefinity-3.6 version.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    17 Dec 2009
    Link to this post
    Hi Jayakrishna,

     It can be done. Below are the steps that you should follow.

    1. Create a new class that inherits from TagsList

    2. Create a property where you will get the blog IDs so you can create a filter

    3.  Override InitializeControls and do not call the base.

    4. Here you need to create a custom data source and bind TagsRepeaterList control. The custom data source should contain the filtered data from the specified posts. You need to loop through all posts from the specified blog and check the tags using GetTags method.

    IList allcontent = tag.TaggedContent;
    foreach (ITaggedContent cnt in allcontent)
    {
       // your logic here
    }

    You may find the following post useful - filter categories by post which describes similar approach.


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jayakrishna
    Jayakrishna avatar
    5 posts
    Registered:
    25 Mar 2009
    17 Dec 2009
    Link to this post
    We have extended the TagsList Control. We are able to retrive the required tags into the blogTags variable shown in the below code but we are not able to bind that object to the repeater.

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Cms.Engine.WebControls.Categories; 
    using Telerik.Cms.Engine.WebControls.Tags; 
    using Telerik.Cms.Web.UI; 
    using System.ComponentModel; 
    using System.Collections; 
    using Telerik.Cms.Engine; 
    using Telerik.Blogs; 
    using Telerik.Cms; 
    using System.Web.UI; 
    using Telerik.Cms.Engine.Data; 
     
     
    namespace ramp 
        /// <summary> 
        /// Summary description for TagsListFiltered 
        /// </summary> 
        public class TagsListFiltered : TagsList 
        { 
            public TagsListFiltered() 
            { 
                // 
                // TODO: Add constructor logic here 
                // 
            } 
     
            [TypeConverter("Telerik.Blogs.WebControls.SelectedBlogsConverter, Telerik.Blogs")] 
            [WebEditor("Telerik.Blogs.WebControls.BlogsSelector, Telerik.Blogs")] 
            public Guid[] SelectedBlogs 
            { 
                get 
                { 
                    return this.selectedBlogs; 
                } 
                set 
                { 
                    this.selectedBlogs = value
                } 
            } 
     
            #region Methods 
     
            protected override void InitializeControls(Control controlContainer) 
            { 
                blogManager = new BlogManager("Blogs"); 
                if (this.selectedBlogs.Length == 0) 
                { 
                    // call the base class we will not change anything. 
                    //base.BindCategories(); 
                } 
                else 
                { 
                    IList<ITag> allTags = new List<ITag>(); 
     
                    IList allBlogs = blogManager.GetBlogs(selectedBlogs); 
                    foreach (IBlog blog in allBlogs) 
                    { 
                        IList blogblogPosts = blog.Posts; 
                        foreach (IContent post in blogPosts) 
                        { 
                            IList postTags = blogManager.Content.GetTags(post.ID); 
                            foreach (ITag tag in postTags) 
                            { 
                                if (!blogTags.Contains(tag)) 
                                { 
                                    blogTags.Add(tag); 
                                }                            
                            }                        
                        } 
                    }                
                     
                    TagsRepeaterCloud.DataSource = blogTags
                    TagsRepeaterCloud.DataBind(); 
     
                    TagsRepeaterList.DataSource = blogTags
                    TagsRepeaterList.DataBind(); 
     
                } 
     
            } 
             
            #endregion 
            #region Private contstraints 
            private Guid[] selectedBlogs = new Guid[] { }; 
            private BlogManager blogManager; 
            #endregion 
        } 


    Attached the screenshot of the output we are getting


    btw we are using sitefinity 3.6
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    17 Dec 2009
    Link to this post
    Hi Jayakrishna,

    First it does not make sense to create blogsList and get all blogs, then clear the list. You have to create new generic list of type ITag. and populate it.

    IList<ITag> filteredList = new List<ITag>();

    You do not see any posts, because you have to subscribe for ItemDataBound event of the Repeater control

    private void TagsRepeaterList_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    ITag tag = (ITag)e.Item.DataItem;
                    HyperLink tagUrl = (HyperLink)e.Item.FindControl("tagLink");
                    tagUrl.Text = tag.TagName;
     
     
                      ....
                           ....
                 }
        }

    I will make a blog posts about this implementation, so you can stay tuned.


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Jayakrishna
    Jayakrishna avatar
    5 posts
    Registered:
    25 Mar 2009
    18 Dec 2009
    Link to this post
    Thanks, that solution helped me a lot.
    I have made a clear post stating the solution for this requirement at

    http://jayakrishnagudla.blogspot.com/2009/12/sitefinity-filtering-tags-for-specific.html

  6. Developer
    Developer avatar
    1 posts
    Registered:
    23 Jun 2009
    24 Jun 2010
    Link to this post
    Where would this fix be installed? My Sitefinity installation does not have an "App_Code" folder.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    24 Jun 2010
    Link to this post
    Hi ,

    Please take a look at ASP.NET Web Site Layout. You could use App_Code or separate class library.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
7 posts, 0 answered