Copied to clipboard

Flag this post as spam?

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


  • Darren Wilson 218 posts 556 karma points
    Aug 06, 2015 @ 10:48
    Darren Wilson
    0

    Display blog entries in date order

    Hi Folks,

    I'm using the blog software that comes with the Fanoe theme when installing Umbraco. I've but together a wee bit of XLST to display the entries, however, it's displaying them in an odd order and not by date.

    the site is: http://www.highnet.com/customer-area/customer-area/

        enter @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
        @{
       //Fetch the blogposts from a certain node id
       var blogPosts = Umbraco.Content(1081);
    
      foreach(var blogPost in blogPosts.Children().Take(3)){
    
            <div class="date">@blogPost.CreateDate.ToLongDateString()</div>
            <h2><a href="@blogPost.NiceUrl()">@blogPost.Name</a></h2>       
            <!--<p>@Umbraco.Truncate(blogPost.Introduction, 0, true)</p>-->
    
      }
    }
    

    How do I modify this to sort by date?

    Thanks in advance!

    Darren

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Aug 06, 2015 @ 11:26
    Dennis Aaen
    101

    Hi Darren,

    I think that this will do what you are after

        enter @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
        @{
       //Fetch the blogposts from a certain node id
       var blogPosts = Umbraco.Content(1081);
    
      foreach(var blogPost in blogPosts.Children().OrderBy("CreateDate desc").Take(3)){
    
            <div class="date">@blogPost.CreateDate.ToLongDateString()</div>
            <h2><a href="@blogPost.NiceUrl()">@blogPost.Name</a></h2>       
            <!--<p>@Umbraco.Truncate(blogPost.Introduction, 0, true)</p>-->
    
      }
    }
    

    Hope this helps,

    /Dennis

  • Per Olsson 47 posts 307 karma points
    Aug 06, 2015 @ 11:28
    Per Olsson
    1

    The following should do it:

    foreach(var blogPost in blogPosts.Children().OrderBy("CreateDate").Take(3)){

  • Carl Jackson 139 posts 478 karma points
    Aug 06, 2015 @ 11:28
    Carl Jackson
    0

    Hi Darren.

    Firstly you've put together some Razor not xslt :)

    however, using TypedContent allows you to use linq (better) and so something like the following (untested)...

        @{
       //Fetch the blogposts from a certain node id
       var blogPosts = Umbraco.TypedContent(1081);
    
      foreach(var blogPost in blogPosts.Children().OrderBy(x=>x.CreateDate).Take(3)){
    
            <div class="date">@blogPost.CreateDate.ToLongDateString()</div>
            <h2><a href="@blogPost.NiceUrl()">@blogPost.Name</a></h2>       
            <!--<p>@Umbraco.Truncate(blogPost.GetPropertyValue("Introduction"), 0, true)</p>-->
    
      }
    }
    

    Thanks

    Carl

  • Darren Wilson 218 posts 556 karma points
    Aug 06, 2015 @ 11:53
    Darren Wilson
    1

    I love this forum!

    Thanks for the quick response guys - all these work!

    Good job I'm off to do some Umbraco training - that will teach me the difference between Razor and XLST ha ha!

  • 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