Copied to clipboard

Flag this post as spam?

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


  • Joao 53 posts 172 karma points
    Aug 07, 2013 @ 12:12
    Joao
    0

    Problems with OrderBy

     Hello.

    I have been reading through a lot of posts but I haven't been able to solve my problem. What I want to do is simple, I want to display a preview of all the blog posts from newer to older. I am able to get all the posts and display them but I can't get them in the order I want. This is my razor script file:

    @inherits umbraco.MacroEngines.DynamicNodeContext  
    @{
    var items = @Model.Descendants("BlogPost").Where("Visible").OrderBy("CreateDate, desc");
    foreach (var item in items)
    {
    <div class="blog_Post">
      <div class="blog_Title">@item.blogPostTitle</div>
      <div class="blog_Date">@item.CreateDate.ToString("dddd MMMM yyyy H:mm") @item.CreatorName</div>
      <div class="blogMainImage"><img src="@Model.MediaById(item.blogMainPicture).umbracoFile" alt=""/></div>
      <div class="blogPreview">@Library.Truncate(@item.blogText,400)</div>     
      <div class="blog_Link"><a href="@item.Url">lue lisää</a></div>
    </div>
    }
    }

    I have tried changing to OrderBy("CreateDate, asc") but nothing changes. I have read that some people use the following syntax: OrderBy("CreateDate desc") but if I change it to that it will give an error and not load.

    I have also tried OrderByDescending(x => x.CreateDate); but it does not load as well.

    Can someone help?

    For the record, I'm using  umbraco v 4.11.3 (Assembly version: 1.0.4760.34993) 

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Aug 07, 2013 @ 12:26
    Jeavon Leopold
    101

    Hi Joao,

    I just tried the below and it worked fine (v6.1.1):

    var items = Model.Descendants("BlogPost").Where("Visible").OrderBy("CreateDate desc");  
    

    Could you try that, if you still get an error we will need to know what it says?

    Thanks,

    Jeavon

  • Joao 53 posts 172 karma points
    Aug 07, 2013 @ 12:29
    Joao
    0

    Ok i feel kinda dumb right now... I just tried it and worked but I could swear it didn't before! Thank you for such a quick reply Jeavon!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Aug 07, 2013 @ 12:30
    Jeavon Leopold
    0

    Np, glad it's sorted!

Please Sign in or register to post replies

Write your reply to:

Draft