More in this section

Forums / Developing with Sitefinity / Randomize content

Randomize content

6 posts, 0 answered
  1. Kalpana
    Kalpana avatar
    27 posts
    Registered:
    18 Dec 2008
    08 Apr 2009
    Link to this post
    Hi

    I was wondering if there was a way to keep changing the content in a well randomly. Like a 'Featured Item' well. Create 3 different related content items - display one in the well. Keep changing the content of this well by displaying one of the 3 content items in some random order.

    Thanks.

    Kalpana
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Apr 2009
    Link to this post
    Hi Kalpana,

    If you want to display some content randomly you could try using RadRotator control or create some schedule content items that will be show or hidden depending on the dates you have specified.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Foodsleuth
    Foodsleuth avatar
    46 posts
    Registered:
    21 May 2008
    09 Apr 2009
    Link to this post
    Is there a built-in Sitefinity facility for scheduled content?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 Apr 2009
    Link to this post
    Hi Foodsleuth,

    There is no built in implementation for scheduled content. This feature will be available for 4.0.

    Here is a sample code that demonstrates this approach.

            ContentManager manager = new ContentManager("News"); 
            IList Items = manager.GetContent();  
            foreach (IContent item in Items)  
            {  
                //READ METAFIELDS  
                DateTime pubDate = (DateTime)item.GetMetaData("Publication_Date");  
                DateTime expDate = (DateTime)item.GetMetaData("Expiration_Date");  
                //get the content for editing  
     
                StagedContent itemToChange = manager.GetStagedContent(item.ID) as StagedContent;  
                //OPTIONALLY CHECK EVEN OR ODD DATES(2,4,6...1,3,5)  
                bool changed = false;  
                if (pubDate.Day % 2 == 0)  
                {  
                    //DAY IS EVEN HERE  
                    DateTime newTime = DateTime.Today;  
                    //SET NEW PUBLICATION DATE  
                    itemToChange.SetMetaData("Publication_Date", newTime.AddDays(5));  
                    //SET NEW EXPIRATION DATE  
                    //THE ITEM EXPIRE IN 30 DAYS FROM NOW ON 
                    itemToChange.SetMetaData("Expiration_Date", newTime.AddDays(30));  
                    changed = true;  
                }  
                else  
                {  
                    //DAY IS ODD  
                    changed = true;  
                }  
                //SAVE CONTENT  
                if (changed)  
                    //SAVE IN DRAFT  
                   itemToChange.Status = ContentStatus.Draft;  
                   manager.SaveContent(itemToChange);  
     
           ..... 
                  ...... 

    I hope this helps.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Kalpana
    Kalpana avatar
    27 posts
    Registered:
    18 Dec 2008
    14 Apr 2009
    Link to this post
    Hi Ivan

    I followed your advice and used the radrotator. I copied the newsRotator code from the KB articles. I implemented it.

    I created 4 test items in the News modules with a category. When I see the page with the newsrotator control - I see all the 4 news items. I am not sure what I doing wrong - I thought it would display 1 at a time and keep changing the content based on my settings.

    Here is how I call the newsRotator on my page :

    <%@ Register TagPrefix="MCCC" TagName="MCCCRadRotator" Src="~/NewsRotator.ascx" %>


             <MCCC:MCCCRadRotator id="RD1" CategoryName="Success Story" runat="server" />


    Please, tell me what I am missing.

    Kalpana
  6. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    20 Apr 2009
    Link to this post
    Hi Kalpana,

    It would be helpful if you can point us the the KB article you used and, more importantly, the code that is using it.

    Regards,
    Dido
    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.
Register for webinar
6 posts, 0 answered