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.
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>-->
}
}
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>-->
}
}
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>-->
}
}
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/
How do I modify this to sort by date?
Thanks in advance!
Darren
Hi Darren,
I think that this will do what you are after
Hope this helps,
/Dennis
The following should do it:
foreach(var blogPost in blogPosts.Children().OrderBy("CreateDate").Take(3)){
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)...
Thanks
Carl
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!
is working on a reply...