More in this section

Forums / Developing with Sitefinity / Can't get News Categories to work

Can't get News Categories to work

29 posts, 0 answered
  1. Jack
    Jack avatar
    10 posts
    Registered:
    31 Jul 2007
    02 Sep 2008
    Link to this post
    Has anyone else come across the problem of news categories not working?

    I'm in the finishing stages of my site and am adding news (just 4 articles so far). I've got news displaying on multiple pages and want relavant news only to show on the pages. This is what the categories are for.

    I've added my list of categories, assigned a category to each piece of news and defined what category each newslist should pick up. However each list is displaying all the news, regardless of what categories are selected.

    Any help? Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Sep 2008
    Link to this post
    Hello Jack,

    Thank you for your question.

    You need to configure CategoriesList control properties in accordance with NewsView control.
    In CategoriesList control you should specify your ProviderName - News, CategoryContentUrl - the place where you want to see the categories and the CategoryKey which will be used for passing data in the query when the category link is pressed. The CategoryKey property form Content list control have to be the same as in NewsView control- NewsCatID.

    Please find the attached screenshot for your convenience.

    Hope this helps.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Jack
    Jack avatar
    10 posts
    Registered:
    31 Jul 2007
    03 Sep 2008
    Link to this post
    Hi Ivan,

    Thanks for you response, I can now work the Categories control which is great, however that wasn't my original problem!

    My problem is that in the NewsList the individual news items aren't being selected by the categories defined in the NewsList control. It is showing all news items regardless of what category they are assigned to.

    e.g. The newslist control is set to only show news items that are in Category 'A', however it is actually showing news from categories 'B', 'C', 'D' etc.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Sep 2008
    Link to this post
    Hi Jack,

    You can try setting the FilterExpression property of the NewsList control with value Category=CategoryName.

    I assume that you are not using the latest release of Sitefinity, because the News List and Single News public controls are obsolete. Please upgrade your product version and use the News View control instead.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jack
    Jack avatar
    10 posts
    Registered:
    31 Jul 2007
    03 Sep 2008
    Link to this post
    Hi Ivan,

    That works but I can only define one category per NewsList, when I try and add another one it errors - is there a specific syntax for adding more than one, currently I am doing:

    Category=CategoryName1;CategoryName2

    I am using version 3.2 but I don't think the Service packs have been applied, I'm aunable to apply them at this time so need a workaround for the time being.

    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Sep 2008
    Link to this post
    Hi Jack,

    This is a known issue and it has already been fixed. The functionality that you want to achieve will be available in our next release.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Randel Bjorquist
    Randel Bjorquist avatar
    8 posts
    Registered:
    25 Jan 2008
    09 Sep 2008
    Link to this post
    Ivan,

    Is there an estimated release date for this functionality?
  8. Randel Bjorquist
    Randel Bjorquist avatar
    8 posts
    Registered:
    25 Jan 2008
    10 Sep 2008
    Link to this post
    Ivan,

    For us, this is an extremely important feature.  And since you've said a fix for this issue has already been completed, is there anyway to get this into a hotfix.  What I really don't want to do is to waste the time writing something you've already done.  Any thoughts, suggestions, or pointers would be greatly apreciated.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 Sep 2008
    Link to this post
    Hi Randel Bjorquist,

    I cannot give you a certain date at this stage, but I assure you that this will be available in our up coming release. We have already fix this issue as I mentioned in my previous post. It is really difficult to say when we will release, because there are a lot of things that we want to improve and make our product more powerful. You can stay informed for product updates subscribing for our Rss feed.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    11 Sep 2008
    Link to this post

    Ivan,

    Ok, since you've said it's fixed, just not released and I really need this ability, can you help with my solution?

    Problem
    I need the ability to assign any or all of the 4 Categories I have, to a specific Event. This feature may need to be used elsewhere; I'm not sure or at that point yet.

    Solution
    I am still thinking of only assign a single Category to an Event, but I do not want my end-users to see a list of Categories like:

    Corporate
    Corporate | Employee
    Corporate | Manager
    Corporate | Supervisor
    Corporate | Employee | Manager
    Corporate | Employee | Supervisor
    Corporate | Manager | Supervisor
    Corporate | Employee | Managers | Supervisor
    Employee
    Employee | Manager
    Employee | Supervisor
    Employee | Managers | Supervisor
    Manager
    Managers | Supervisor
    Supervisor

    My solution entails using either a CheckedListBox or 4 CheckBoxes (one for each of the base Categories) and the 15 listed Categories. If I use the CheckedListBox, I want to make sure I filter out all Categories with “|”, a pipe character, leaving only the base Categories. Once the end-user clicks the “Save Changes” button, I would then parse out the CheckedItems and assign the appropriate Category.

    My questions start with, what control and page do I modify and what pointers can you give me?

  11. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    12 Sep 2008
    Link to this post
    Hi Randel,

    it is possible to change the default drop down list for categories with your own control. Here is what you will need to do:

    1. Create a new control (user control or custom control, whichever you prefer). This new control will be used as the user interface for selecting categories on the admin side.
    2. Make sure this control implement ITextControl interface. The Text property which ITextControl mandates will be used by Sitefinity to acquire the selected category when user clicks "Save"
    3. Implement the control fully. I've attached a sample in which I've created a control which uses RadEditor for user interface of a meta field. You'll be using similar approach, except that you won't have RadEditor but rather checkboxes.
    4. Modify the insert and update templates of the module you want to use this new control for selecting categories. For example, if it is News module, you will open ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelInsert.ascx and ~/Sitefinity/Admin/ControlTemplates/News/ControlPanelUpdated.ascx. Locate the CategoryField control there and replace it with your new control. Make sure that your new control has the id="Category" (that is how Sitefinity knows for which meta field this control is used - id must match meta field key).

    And that should be it. I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Kind regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  12. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Hey Vlad, thanks for the information.  I'll give it a try.  I have another thought/question.  If I do this, how will my code be affected by the next release/update?  I'm making the guess the next release/patch will contain the fix for multiple categories.  Lastly, in your opinion as a Telerik employee/developer, is this the correct solution or do you have a better one in mind?

    Thanks again.
  13. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Sorry Ivan, my bad typing.
  14. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    12 Sep 2008
    Link to this post
    Hi Randel,

    on the upgrade you will obviously have to make sure not to override the template you have changed. If you do so, you will need to again replace CategoryEditor with your own control.

    As for my opinion on this... I don't know enough about the scenario to say with certainty, but the fact is that our lack of support for hierarchical categories does not leave you with much choice - so if it works it's a good solution.

    I am sorry that you have to work around this issue - but the new advanced (and backward compatible!) Generic Content API will be implemented for Sitefinity 4.0 (lots of it is already done) and hierarchical categories will be present.

    Let us know if there is anything else we can do for you.

    Regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Ivan, I'm looking at the unzipped project you attached and I don't think I see what you are talking about.  I don't see a RadEdit control.  I see a fix that creates a DataSource and handles the filtering of such contect by Tags.  What am I missing?
  16. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    12 Sep 2008
    Link to this post
    Hi Randel,

    I have sent an answer to another ticket with that attachment few minutes ago. I am not sure was it to you. The attachment on this ticket however is correct - EditorMetaField.rar. I have just double checked it.

    The other attachment regards the issues with Blog Posts and sort expression when filtering by category.

    Please try to download the attachment from this ticket again.

    Greetings,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  17. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Hey Ivan, I see the attachment and have downloaded it, but the only cs file I see is the "EventsViewFix.cs".  Am I still missing something?
  18. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Hey Ivan, I've finally got the code you're talking about.  I'll look at it and see what questions I still have.  Thanks again for all your help.
  19. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Ivan, if I wanted to use a CheckListBox, how do I retrieve that information from the database and then filter it so only the "base" Categories are visible?
  20. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    12 Sep 2008
    Link to this post
    Hi Randel,

    to get the Categories I strongly suggest you use Sitefinity API. Namely, working with database directly is generally not something you would want to do, because we may change the table names or field names and your code would broke, but when you work with the API even if we change something we always make sure that the changes are backward compatible.

    To find out more about using Sitefinity API for working with categories (which are part of Generic Content module), please take a look at the following article:
    http://www.sitefinity.com/help/developer-manual/categories-get.html

    You will receive a flat list of categories. How are you going to make them hierarchical depends on the logic you plan to implement, but I would guess it will involve some level of string manipulation (e.g. splitting the string by | sign and then taking the last or first...)

    I hope you will find this information helpful. Let us know if there is anything else we can do for you.

    Sincerely yours,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  21. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Ivan,

    I've done what you suggested.  However, now that I've updated the ControlPanelInsert.ascx and ControlPanelEdit.ascx, of the Sitefinity | Administrator | Events folder, I get the following error, any thought?
     

    Server Error in '/Public.KyukiDo' Application.

    Unable to cast object of type 'ASP.usercontrols_emarketing_categorychecklistbox_ascx' to type 'Telerik.Cms.Engine.WebControls.Categories.CategoriesField'.

    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.InvalidCastException: Unable to cast object of type 'ASP.usercontrols_emarketing_categorychecklistbox_ascx' to type 'Telerik.Cms.Engine.WebControls.Categories.CategoriesField'.

    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:

    [InvalidCastException: Unable to cast object of type 'ASP.usercontrols_emarketing_categorychecklistbox_ascx' to type 'Telerik.Cms.Engine.WebControls.Categories.CategoriesField'.]
       Telerik.Cms.Engine.WebControls.Admin.EditorContainer.LoadOptionalControls() +591
       Telerik.Cms.Engine.WebControls.Admin.ControlPanel.SetEditContainer(Int32 idx, StagedContent stg) +100
       Telerik.Cms.Engine.WebControls.Admin.ControlPanel.CreateEditView() +373
       Telerik.Cms.Engine.WebControls.Admin.ControlPanel.CreateChildControls() +1085
       Telerik.Events.WebControls.Admin.ControlPanel.CreateEventsContentView() +32
       Telerik.Events.WebControls.Admin.ControlPanel.CreateChildControls() +243
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.WebControls.CompositeControl.RecreateChildControls() +21
       Telerik.Cms.Engine.WebControls.Admin.ControlPanel.set_Mode(Modes value) +823
       Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Grid_RowCommand(Object sender, GridViewCommandEventArgs e) +221
       System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +105
       System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +76
       System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +199
       System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
  22. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    12 Sep 2008
    Link to this post
    Wong file path.  It should have been: ROOT | Sitefinity | Admin | ControlTemplates | Events | ControlPanelInsert.ascx & ... | ControlPanelEdit.ascx.
  23. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    15 Sep 2008
    Link to this post
    I still get the error above.  The "wong", should have been "wrong", path comment was simply to correct an error in my previous post.  Ivan, do you have any thoughts as to why I'm getting this error and how to correct it?
  24. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    15 Sep 2008
    Link to this post

    Ivan, what might help is if you could you show me how Telerik creates their current <sfCtg:CategoriesField ID="Category" runat="server" /> control?

    Right now, the code for my control looks like: 

    using
    System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class UserControls_EMarketing_CategoryCheckListBox : UserControl, ITextControl
    {
     
    protected void Page_Load(object sender, EventArgs e){
    }

     
    #region ITextControl Members

        string ITextControl.Text{
          get{
            ListItem Category = null;
            
            string
    TmpTxt = string.Empty;
            const string Delimeter = " | ";
           
            for
    (int i = 0; i > cblst_Categories.Items.Count; i++){
              Category = cblst_Categories.Items[i];
             
              if
    (Category.Selected){
                TmpTxt += string.Format("{0}{1}",
                                        Delimeter,
                                        Category.Text);
              }
            
    }

            return
    TmpTxt.Substring(0, TmpTxt.LastIndexOf(Delimeter));
          }

         
    set{
            string TmpTxt = value;
            ListItem Category = null;
           
            for
    (int i = 0; i > cblst_Categories.Items.Count; i++){
              Category = cblst_Categories.Items[i];
              Category.Selected = TmpTxt.Contains(Category.Text);
            }
          }
        }
      
      #endregion

    }

    and the code for ControlPanelInsert.ascx and ControlPanelEdit.ascx have been updated to look like:

    :
    <fieldset class="set">
      <ol class="setIn">
        <li class="catSel clearfix">
          <asp:Label ID="Label4" AssociatedControlID="Category" runat="server">
            <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Category %>" />
            <em id="Em1" runat="server" />
          </asp:Label>
          <%--<sfCtg:CategoriesField ID="Category" runat="server" />--%>
         
    <emuc:CategoryCheckListBox ID="Category" runat="server" />
        </li>
      </ol>
    </fieldset>
    :

    Can you please tell me what I'm missing?

  25. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    17 Sep 2008
    Link to this post
    Ok, since I'm having the above problem and not getting any help with it, I thought of another solution to try.  I thought I would just modify the existing "CategoriesField" control.

    I've made a backup of the original control file and added a code behind file.  The new/modified control implements the ITextControl interface (like I was instructed to do above) and the code behind has the code below.

    I now have a new problem.  It seems as if this code do not get executed.  I've tried walking through the code, I've placed break points on each the "get" and "set", but it never gets entered.  Does anyone have any ideas as to what I'm missing?

    string ITextControl.Text{
     
    get{

        ListItem Category = null;
       
        string TmpTxt = string.Empty;
        const string Delimeter = " | ";
       
        for
    (int i = 0; i > categoriesList.Items.Count; i++){
          Category = categoriesList.Items[i];
         
          if
    (Category.Selected){
            TmpTxt +=
    string.Format("{0}{1}", Delimeter, Category.Text);
          }
        }
       
        return TmpTxt.Substring(0, TmpTxt.LastIndexOf(Delimeter));
      }
     
     
    set{
        string TmpTxt = value;
        ListItem Category = null;
       
        for
    (int i = 0; i > categoriesList.Items.Count; i++){
          Category = categoriesList.Items[i];
          Category.Selected = TmpTxt.Contains(Category.Text);
        }
      }
    }

  26. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    26 Sep 2008
    Link to this post
    Hi Randel,

    the error you are getting is due to the architectural mistake we have made with this control. Namely, the container is looking for the control of type CategoriesField, where we should have made it look for the ITextControl or ICategoriesField. I have fixed this issue and it will be released in the next release due by the end of this month or in the first days of October.

    I hope that you will be able to wait for the upgrade. Once you upgrade you will be able to proceed in the way I have suggested in my previous posts.

    All the best,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  27. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    07 Oct 2008
    Link to this post

    Hey Ivan,

    I just wanted to get an ETA on the next release.

    Thanks

  28. Joe
    Joe avatar
    138 posts
    Registered:
    24 Sep 2012
    07 Oct 2008
    Link to this post
    Hi Randel,

    Thanks for contacting us.

    The 3.5 version of Sitefinity is scheduled for Wednesday, October 8th. Upgrading current projects will be something like this, which is just replacing some files and updating your Web.config accordingly. Please let us know if you have any other questions.

    Sincerely yours,
    Joe
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  29. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    07 Oct 2008
    Link to this post
    Hey Joe,

    Thanks for the quick update.
Register for webinar
29 posts, 0 answered