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
    0

    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:

    Home
       About
       Media
          Blog
             -a blogentry
          News
             -a newsentry

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

    Thanks! 

     

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

    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

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

    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
    0

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

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Nov 06, 2011 @ 16:03
    Sebastiaan Janssen
    0

    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 /> }
  • 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