Copied to clipboard

Flag this post as spam?

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


  • Roger Withnell 128 posts 613 karma points
    Nov 16, 2015 @ 13:56
    Roger Withnell
    0

    Order items by a date property

    I'm listing the children of a page as follows:

        var page = Umbraco.Content(FolderId);
        var vPageName = page.name;
    
        foreach (var child in page.Children)
    

    How do I put the children in descending order using a date property?

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 16, 2015 @ 14:04
    Dennis Aaen
    101

    Hi Roger,

    What you can do is to add .OrderBy to your foreach statement, so your code should look something like this,

    var page = Umbraco.Content(FolderId);
    var vPageName = page.name;
    
    foreach (var child in page.Children.OrderBy("date desc"))
    

    Where "date" is the property alias of your date field. If you use "CreateDate", then you will sort on when the pages, was created.

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft