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

Forums / Developing with Sitefinity / Different categories for different blogs

Different categories for different blogs

20 posts, 0 answered
  1. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    10 Sep 2009
    Link to this post
    Hi

    I would like to create 2 blogs with different categories for each blog. 
    But, I found that the categories I created in one blog can be seen in other blog too. However, the posts are different. What I need is, when I click on a particular blog, I want to show the categories related to that blog only.

    Can anyone tell me how to achieve this?


    -Thanks
     Dinesh
  2. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    10 Sep 2009
    Link to this post
    I am currently using Sitefinity 3.6 version.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Sep 2009
    Link to this post
    Hello Dinesh,

    It is possible.

    1. Map CategoriesView template for BlogCategoriesView view.
    2. Create a code behind of the template.
    3. Subscribe for NodeDataBound event.
    3. Get the current blog ID.
    4. Show or hide some categories.

    Sample code:

       protected void Page_Load(object sender, EventArgs e) 
        { 
            categoriesTreeView.NodeDataBound += new Telerik.Web.UI.RadTreeViewEventHandler(categoriesTreeView_NodeDataBound); 
        } 
     
        void categoriesTreeView_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
        { 
            ContentManager manager = new ContentManager("Blogs"); 
            ICategory category = (ICategory)e.Node.DataItem; 
            IList categoryTree = manager.GetCategoriesTree(category); 
            foreach (ICategory cat in categoryTree) 
            { 
                if (cat.CategoryName == "b2"
                { 
                    e.Node.Visible = false
                } 
            } 
        } 

    getting the ID of the current blog.

    BlogCategoriesView itemPreview = (BlogCategoriesView)this.Parent.Parent; 
    Guid contentID = new Guid(CmsHttpRequest.Current.QueryStirng[itemPreview.ParentIdKey]) 


    Kind regards,
    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.
  4. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    10 Sep 2009
    Link to this post
    Wait... so, if you have more than one blog, there is no easy, built-in way to show categories used on each blog (and not on other blogs)?  But there IS a way to show only posts from a particular blog in BlogPosts control, so why isn't there a way to show the associated blog categories, too?  It only makes sense to do so.

    Unless I'm missing something?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Sep 2009
    Link to this post
    Hi Marko,

    The code shows  sample implementation for the backend where we have view. Categories are common for all posts. We associate posts with categories not blogs with categories although this is reasonable we we have though about this several times. The code of the "problem" is missing straight relation between ParenId - the Blog and a  category. The "Category" is a metadata and it is related with a content items.

    Regards,
    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.
  6. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    10 Sep 2009
    Link to this post
    I understand.  I guess I'm just thinking in practical terms (that my site visitors might be thinking in). Even though blogs are not DIRECTLY related to categories, they are related through the posts themselves (blog is related to a post which is related to a category), like you said.  And for that reason, there SHOULD already be a built-in functionality in Sitefinity that allows to display blog categories that are related only to [posts in] a single blog.

    In my example, I already have one blog, which has its own CMS page containing a BlogPosts control (showing only that blog).  On that same page, I'm using a CategoriesTree to show the categories used in this blog.  However, now I need to add another blog, somewhat UNRELATED to the first blog (when it comes to the type of information in it), and it doesn't really make any sense to show ALL blog categories in a CategoriesTree.

    In my opinion (and maybe this is just me), but Blogs, such as they are in Sitefinity, are not really "blogS" but more like ONE SINGLE BLOG, with multiple "sub-blogs."  So I suppose it might be just the terminology that's confusing me. :-)
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Sep 2009
    Link to this post
    Hello Marko,

    You can try the following: Create a new provider for blogs. For instance use different application name so that your blogs and post will not be visible through the providers. Then you can create several categories for the newly added provider. Drop CategoriesTree control. Expand Data category of the control and set ProviderName property to the name of your new blog  provider. This will force binding the categories only for this provider.

    I hop this helps.

    All the best,
    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.
  8. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    10 Sep 2009
    Link to this post
    Thanks Ivan, I'll look into that, too.  I also decided to take this opportunity to see if I can work within the current Blogs framework, such as it is--maybe all I need to do is think of clever categories that DO make sense across blogs?  I'll see.  Sometimes it takes a change in thinking, rather than a change in infrastructure.  :-) 
  9. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    11 Sep 2009
    Link to this post
    Hello Ivan and Marko,

    Thanks for your discussion. This really clarifies things. 
    Can I create a new module which inherits Blogs module? I need the exact implementation of Blogs module and no other extra functionality is needed. 
    Can you send me any code on how to implement this?



    -Thanks

  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Sep 2009
    Link to this post
    Hi Dinesh,

    You need just to create a new class that inherits from BlogsModule and override Title and Name properties.

    public class Class1 : BlogsModule 
        public Class1() 
        { 
        } 
     
        public override string Title 
        { 
            get 
            { 
                return "MyTitle"
            } 
        } 
        public override string Name 
        { 
            get 
            { 
                return "MyName"
            } 
        } 


    Best wishes,
    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.
  11. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    11 Sep 2009
    Link to this post
    HI Ivan...

    If I do so, do I get all the categories which I created in blogs? If so, I don't want the categories to appear in my new module. 
    I want to create a new module which has all the features of Blogs but I don't want to carry the blogs or categories or posts that are created in blogs module.
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Sep 2009
    Link to this post
    Hello Dinesh,

    Then you need to create a new provider for your module. The provider should inherits from DefaultProvider which will be almost the same as creating a new module. Another possible option could be overriding the BlogsControlPanel and setting hardcoded provider for the copy of BlogsModule.

     public override string ProviderName 
        { 
            get 
            { 
                base.ProviderName = hardCodedProvider; 
                return hardCodedProvider; 
            } 
            set 
            { 
                base.ProviderName = hardCodedProvider; 
            } 
        } 

    All the best,
    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.
  13. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    12 Sep 2009
    Link to this post
    Hi Ivan,

    Thanks for your assistance... Could you make a little bit clarification. 
    What is this hardCodedProvider? Does it takes whatever name I give? If not so how to declare or define that hardCodedProvider? 
    And finally any changes to web.config is required?


    -Dinesh
  14. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    12 Sep 2009
    Link to this post
    I created a class FAQModule which has the following code

    public class FAQModule:BlogsModule 
        public FAQModule() 
        { 
            // 
            // TODO: Add constructor logic here 
            // 
        } 
     
        public override IList<Telerik.Web.IToolboxItem> Controls 
        { 
            get { return null; } 
        } 
         
        public override string Description 
        { 
            get { return "Frequently Asked Questions"; } 
        } 
     
        public override string Name 
        { 
            get { return "FAQ"; } 
        } 
     
        public override string Title 
        { 
            get { return "FAQ"; } 
        } 
     
        public override Control CreateControlPanel(TemplateControl parent) 
        { 
            return new FAQControlPanel(); 
        } 
     
          
        
     

    and another class for controlpanel named FAQControlPanel
    public class FAQControlPanel : ControlPanel<FAQControlPanel> 
        public FAQControlPanel() 
        { 
            // 
            // TODO: Add constructor logic here 
            // 
        } 

    and added a single line in web.config
    <cmsEngine defaultProvider="Generic_Content"
                <providers> 
                    <clear/> 
                    <add name="FAQ" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" securityProviderName="" allowVersioning="False" applicationName="/FAQ" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data" />                 
                </providers> 
    <cmsEngine /> 

    Without the override method for controlpanel I got the new module same as blogs. But, after writing the overrride method for controlpanel it is giving the following error
    Object reference not set to an instance of an object. 
     
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.  
     
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. 
     
    Source Error:  
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
     
    Stack Trace:  
     
     
    [NullReferenceException: Object reference not set to an instance of an object.] 
       Telerik.Cms.Web.UI.Backend.BackendBreadcrumb.CreateChildControls() +39 
       System.Web.UI.Control.EnsureChildControls() +87 
       System.Web.UI.Control.PreRenderRecursiveInternal() +44 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 
     


    Is anything missing out here?
    Where to include the override method for ProviderName?
    Do I need to add anything else for FAQ provider other than I added in web.config file?


    -Dinesh


  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Sep 2009
    Link to this post
    Hi Dinesh,

    hardCodedProvider is a string which is the name of a provider you would like to use. Also I could not see any code that shows implementation of your provider. In your provider declaration you use type"Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data", but your module inherits from BlogsModule which type is "Telerik.Blogs.Data.DefaultBlogProvider, Telerik.Blogs.Data"

    Best wishes,
    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.
  16. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    14 Sep 2009
    Link to this post
    Can you give a sample code on how to create a provider?
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    14 Sep 2009
    Link to this post
    Hello Dinesh,

    You can take a look at our Sample Contacts module.

    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.
  18. Aleksey Smoljanko
    Aleksey Smoljanko avatar
    2 posts
    Registered:
    08 Jun 2012
    26 Sep 2011
    Link to this post
    Hello

    Please tell me how to implement this:
    1 Blog -> 1 category list.
    2 Blog -> 2 category list.
    3 Blog -> 3 category list.
    ps (every blog has its own list of categories)

    Dinesh option is not suitable, tk is not known how the name is a blog and how many and which categories will be

    Thanks Aleksey
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    27 Sep 2011
    Link to this post
    Hi Aleksey ,

    You can create a root category per blog and then filter the Category Tree control by parent. This is the solution that would not require custom coding.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  20. Aleksey Smoljanko
    Aleksey Smoljanko avatar
    2 posts
    Registered:
    08 Jun 2012
    27 Sep 2011
    Link to this post
    Hello Ivan,

    I do not understand how to do it in the admin panel?
    That is created root category and parent category
    but as these categories privizat blog? to see category of nebyli blog2 and blog3?

    Thanks Aleksey.
Register for webinar
20 posts, 0 answered