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

Forums / Developing with Sitefinity / Custom Blog Catagories List

Custom Blog Catagories List

6 posts, 2 answered
  1. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    27 Jul 2009
    Link to this post
    Hi All,

    I am currently trying to create a custom Catagories list for my blogs as the 'CategoriesTree' template is not appropriate for what I need. I have managed to get a list of Blog Catagories and bind them to a Datalist, however I need to be able to show the number of items in that catagory and when I cast each item as

    Telerik.Cms.Engine.ICategory

    the property 'ContentCount' returns '0'. How can I get the total count of the items in the catagory?

    Thanks in advance

    Jodie

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    27 Jul 2009
    Link to this post
    Hi Jodie,

    Below is a sample code that illustrates how to get the number of categories in a category.

        void btn1_Click(object sender, EventArgs e) 
        { 
            this.cntManager = new ContentManager(); 
            IList listofCategories = cntManager.GetCategories(); 
     
            foreach (ICategory category in listofCategories) 
            { 
                var currentCat = cntManager.GetCategory(category.ID) as ICategory; 
                currentCat.ContentCount = GetCategoryCount(currentCat); 
     
               Response.Write(currentCat.ContentCount.ToString()); 
            } 
     
        } 
     
        int GetCategoryCount(ICategory category) 
        { 
            this.cntManager = new ContentManager(); 
            IList categoriesTree = cntManager.GetCategoriesTree(category); 
            var filter = new List<IMetaSearchInfo>(); 
            foreach (ICategory categoryItem in categoriesTree) 
                filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", categoryItem.CategoryName, SearchCondition.Equal, JoinType.And)); 
     
            int contentCount = cntManager.GetContent(filter.ToArray()).Count; 
            return contentCount; 
        } 
     
     
        private ContentManager cntManager; 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  3. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    27 Jul 2009
    Link to this post
    Thanks thats awesome!!!

    As per usual Ivan... you are the man :)

    I looked at the Filters and the MetaSearchInfo, however I was a little confused about how to implement.

    Thank you for the code and quick response.

    Love Telerik....... Love Life!

    Cheers

    Jodie
  4. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    27 Jul 2009
    Link to this post
    Ok now I am wondering.... how do you create the joined data (CatagoryID to ParentCatagoryID) to bind to the RADTreeview in the CatagoryTree?
     
    I can think of (what seems to me) a along winded way of doing this.

    How do you achieve this in the CatagoryTree template?

    Apologies, I probably should have included this earlier :(

    Cheers

    Jodie
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    27 Jul 2009
    Link to this post
    Hello Jodie,

    You can use a list of categories to determine whether one category is root or not.

    foreach (ICategory cat in allCategories) 
                { 
                    bool root = true
                    foreach (ICategory cat1 in categories) 
                    { 
                        if (cat.ParentCategoryID == cat1.ID) 
                        { 
                           root = false
                        } 
                    } 
                    if(root) 
                    { 
                     // do something 
                    } 

    Then you can loop through RadTreeNodes of the root items list.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  6. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    28 Jul 2009
    Link to this post
    Thanks again Ivan.

    This is how I thought it might be done, however I thought you may have another trick up your sleeve.

    Cheers

    Jodie
Register for webinar
6 posts, 2 answered