Copied to clipboard

Flag this post as spam?

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

  • Little North 9 posts 75 karma points
    Nov 05, 2011 @ 12:05
    Little North

    Second level order by

    Hi im new to Umbraco and must say I LOVE IT, I just have a newbie question when working with razor

    My site is set up like this:

             -a blogentry
             -a newsentry

    Say I want to get all blog and news items and order them by createDate.



  • Anthony pj 40 posts 63 karma points
    Nov 05, 2011 @ 15:52
    Anthony pj

    To get the children of a particular document type the following will work ..but you willhave to replace Textpages with the parent document type alias of area you wish to collect ie Blog

        @foreach (var item in @Model.Textpages.Where("Visible").OrderBy("createDate"))
        <li><a href="@item.Url">@item.Name</a></li>

    Or are you asking to collect and order both news and blog item in the same list ?

  • Little North 9 posts 75 karma points
    Nov 05, 2011 @ 16:16
    Little North

    yes i want both to be listed and in the same feed

  • Sebastiaan Janssen 5017 posts 15332 karma points MVP admin hq
    Nov 06, 2011 @ 16:03
    Sebastiaan Janssen

    You can do it like so: 

        //Get the rootnode of the website
    var siteRoot = Model.AncestorOrSelf(1);
    //From that node on look at all of it's descendants and find the ones with nodetype blog or news var updates = siteRoot.Descendants().Where("NodeTypeAlias == \"BlogPost\" || NodeTypeAlias == \"NewsItem\"").OrderBy("CreateDate"); } //List your nodes @foreach(var item in updates) { @item.Name<br /> }
Please Sign in or register to post replies

Write your reply to: