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 123 posts 608 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 4457 posts 17970 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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies