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

Forums / Developing with Sitefinity / Create a flag for News stories

Create a flag for News stories

10 posts, 0 answered
  1. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    26 Aug 2010
    Link to this post
    I would like to flag certain new stories so that I can place it as First second and third to be displayed. I also want to set this up that a new story and can have this flag set and the original flagged stroy will no longer be flagged.

    If this is not clear let me know. I can give you an example.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Aug 2010
    Link to this post
    Hi Steven Lancaster,

    Where you want to do this backend or front end?

    1. For flag you have to create a custom metakey that you can later read.

    2. The public control NewsView uses a repeater. You have to override CreateDataSource method and there re order the list of IContent items depending on the flag - just read the metakey value for each IContent.

    3. Backend - there we use Web Service. If you want to make any modifications the easiest way will be to sort the grid by the custom metakey inside DataBindGrid js function of NewsItemsList external template. For some more complex cases you will need a custom web service.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    26 Aug 2010
    Link to this post
    Hi Steven,

    I am not sure I got what you mean. But let's say you're working with news items. You can create a new meta data for the news items i.e Ordinal of type integer set the default to let's say 4 then for those items that you want to show as first and second and third you can set the Ordinal values accordingly. In the NewsView control you can sort by the Ordinal in an ascending order and hence you will get your items to show at the beginning and also you can modify the value of the ordinal for each item.

    Best,

    George
  4. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    26 Aug 2010
    Link to this post
    I would love to see some sample code and I will explain in more detail what I am trying to do.

    1. Have users create a news story
    2. Have a field marked as 1, 2 or 3
    3. in 2 days when they add another story and and make them 1, 2 or 3 unmark the old stories, but they may decide to keep the old story 1 and change some of the new stories to 2 and 3 or just keep the old ones and change one new story to 2 but keep the old 1 and 3.
    4. Then based on this number I will display the story on the homepage

    The only reason this is neccasary is because we have stories we may want to run as the TOP news story for several day even though we are adding other stories during this time. This is to ensure that the story stays as the "TOP STORY" so rather than do it by date I would love to have some kind of system in place to allow the user to decide what order they want it in.

    Again some sample code or close enough code would be awesome.

    Thanks in advance

    Steve

  5. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    26 Aug 2010
    Link to this post
    Hi Steven,

    Please check the following blog here regarding how to add custom fields to existing sitefinity modules. In your case you will need a metakey of type Integer which you can call Ordinal which you can default to 0. In the news backend you can set the Ordinal to a number > 0 for those news items you want to show on the page, the rest will keep the 0 ordinal. Then you can sort your news in the news view by Ordinal in a descending order.

    Hope this was helpful enough.

    Best,

    George
  6. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    26 Aug 2010
    Link to this post
    George,

      What happens when I add a new story and want it to be 1 will it automatically pull the last one?
  7. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    26 Aug 2010
    Link to this post
    Ideally you will have to keep only 3 news stories with an ordinal value otherwise you will have several news stories having the ordinal 1 2 or 3 and which will be displayed on top or you can keep increasing your ordinal as you add new stories hence they will always display on top.
  8. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    26 Aug 2010
    Link to this post
    I get creating the Metafield and Ordinal Value but I guess my problem comes in is. I have 3 stories already set to 1, 2 and 3. Now I have 3 new stories I want to set to 1,2 and 3. I don't want them to have to go into the old stories and reset the value to 0 I want it to automatically do it when They set a new story to whatever value. Like I have a new story I want it to be 2 but I have an old story that is already 2 so I want the new story to set the old story to 0 and set the new story to 2.

    That is really where my confusion and not know comes in. I am not sure how to build that process.


    Thanks
    Steve
  9. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    26 Aug 2010
    Link to this post
    Hi Steven,

    You can try to do the following:

    1- Create a custom new News Item class that inherits from the original and apply your custom logic

    I have created the class for you:

    public class CustomNewsItemNewView : NewsItemNew
    {
        public const string LAYOUT_TEMPLATE_PATH = "~/Sitefinity/Admin/ControlTemplates/News/NewsItemNew.ascx";
         
        public override System.Type LocalizationAssemblyInfo
        {
            get
            {
                return typeof(NewsItemNew);
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
     
        public override System.Type AssemblyInfo
        {
            get
            {
                return typeof(NewsItemNew);
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
     
        public override string LayoutTemplatePath
        {
            get
            {
                return LAYOUT_TEMPLATE_PATH;
            }
            set
            {
                base.LayoutTemplatePath = value;
            }
        }
     
        protected virtual TextBox OrdinalTextBox
        {
            get
            {
                return base.Container.GetControl<TextBox>("Ordinal", false);
            }
        }
     
        protected override void SaveContent()
        {
            if(OrdinalTextBox != null && int.Parse(OrdinalTextBox.Text) > 0)
            {
                
    var ordinalValue = int.Parse(OrdinalTextBox.Text);
     
                var manager = new NewsManager("News");
     
                foreach (IContent newsItem in manager.Content.GetContent())
                {
                    if(int.Parse(newsItem.GetMetaData("Ordinal").ToString()) == ordinalValue)
                    {
                        newsItem.SetMetaData("Ordinal", 0);
                    }
                }
            }
     
            base.SaveContent();
        }
    }

    2- Add the following to the configuration file 

    <viewSettings hostType="Telerik.News.WebControls.Admin.NewsItemsView, Telerik.News">
      <views>
        <remove name="NewsItemNew"></remove>
        <add name="NewsItemNew" viewType="CustomNewsItemNewView, App_Code"></add>
      </views>
    </viewSettings>

    Best,

    G
  10. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    26 Aug 2010
    Link to this post
    George

    That is awesome..

    Thank You SOOOOOO Much!!
Register for webinar
10 posts, 0 answered