Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Taka 1 post 71 karma points
    Dec 11, 2017 @ 21:45
    Taka
    0

    Get items from three lists and then randomize their order

    Hello,

    I am pulling data from three sources that I have collected from the Umbraco query command.

        Umbraco.TypedContent(1132).Children()
                            .Where(x => x.IsVisible())
                            .OrderBy("CreateDate");
    Umbraco.TypedContent(1131).Children()
                            .Where(x => x.IsVisible())
                            .OrderBy("CreateDate");
    Umbraco.TypedContent(1130).Children()
                            .Where(x => x.IsVisible())
                            .OrderBy("CreateDate");
    

    These are posts I've made and I am trying to funnel the most recent 3 from each of them into a list and then randomize the order before using a for each statement to publish on a "whats new" template.

    I've tried a couple different methods but I can't seem to be able to create a ipublished content list that will accept these data types.

    Does anyone know if this is possible?

    Huge thanks in advance :)

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 11, 2017 @ 22:12
    Alex Skrypnyk
    100

    Hi Taka

    You need something like that:

    var list1 = Umbraco.TypedContent(1132).Children()
                        .Where(x => x.IsVisible())
                        .OrderBy("CreateDate").Take(3).ToList();
    
    var list2 = Umbraco.TypedContent(1131).Children()
                        .Where(x => x.IsVisible())
                        .OrderBy("CreateDate").Take(3).ToList();
    
    var list3 = Umbraco.TypedContent(1130).Children()
                        .Where(x => x.IsVisible())
                        .OrderBy("CreateDate").Take(3).ToList();
    
    list1.AddRange(list2);
    
    list1.AddRange(list3);
    
    var randomizedList = list1.RandomOrder();
    
Please Sign in or register to post replies

Write your reply to:

Draft