More in this section

Forums / Developing with Sitefinity / Blog Categories

Blog Categories

3 posts, 1 answered
  1. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    09 Oct 2009
    Link to this post
    Hi I'm developing a site with three blogs and I want to display a list of categories for each blog.  I've figured out how to grab all categories for all blogs and I'm trying to figure out how to grab the categories for a specific blog.  Here's my code:

        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack && SelectedBlogs != null
            { 
                Telerik.Cms.Engine.ContentManager contentManager = new ContentManager("Blogs");             
                IList listOfCategories = contentManager.GetCategories(); 
                rptCategories.DataSource = listOfCategories; 
                rptCategories.DataBind(); 
            } 
        } 
     
        protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e) 
        { 
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
            { 
                Telerik.Cms.Engine.ContentManager contentManager = new ContentManager("Blogs"); 
                Literal litLink = (Literal)e.Item.FindControl("litLink"); 
                ICategory category = ((Telerik.Cms.Engine.ICategory)e.Item.DataItem); 
                litLink.Text = "<a href=\"?BlogCatID=" + category.ID.ToString() + "\">" + category.CategoryName + "</a> (" + category.ContentCount + ")"
            } 
        } 
     

    Thanks in advance!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Oct 2009
    Link to this post
    Hi Devin,

    I'm trying to figure out how to grab the categories for a specific blog.

    Categories are metadata. They are associated with content items, not with blogs. You can get all categories for a given provider as you have done or get the category from IContent object.


    // GETS CATEGORY FOR A PROVIDER
    var bManager = new BlogManager("Blogs");
    Telerik.Cms.Engine.ICategory getCategoryForPRovider = bManager.Content.GetCategory("TestCategory");
    // EACH CATEGORY IS A METADATA IT IS NOT RELEATED TO THE BLOG - IBLOG OBJECT
    IContent cnt;
    string categoryName = cnt.GetMetaData("Category").ToString();

    For getting a list of Items that are categorized with a specific category you can use MetaSearchInfo filter or better ContentFilterBuilder. I hope this helps.

    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.
    Answered
  3. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    09 Oct 2009
    Link to this post
    That did it!  Thanks loads Ivan.
Register for webinar
3 posts, 1 answered