Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello everyone,
I have a macro that pulls out some info from all pages with doctype 'article'
The code is as follows:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var home = CurrentPage.Site(); var postNodes = home.Descendants("article"); } @foreach (var item in postNodes) { <div class="article"> <p class="tag">@item.tag</p> <a href="@item.url"><img class="thumbnail" src="@item.thumbnail"/></a> <a href="@item.url"><h1>@item.title.ToUpper()</h1></a> @Html.Raw(item.snippet) <a class="continueLink" href="@item.url">[ Continue reading.. ] </a> </div> }
The only problem I am having, is the output is listed in order of tree position, however I want them to be showed in date order (newest first).
Is there a quick fix?
Thanks in advance!
-Jedd
postNodes.orderBy(x=>x.GetPropertyValue
Hi Jedd,
You have to add ordering as said Yasir, I would suggest for you to use createdDate field which is general for Umbraco nodes, like that:
var postNodes = home.Descendants("article").OrderBy("createDate desc").ToList();
Thanks,
Alex
Also be aware that dynamic objects has this strange ways for sorting - OrderBy("createDate desc"). Much better will be to use strongly typed models, sorting will be much easier to understand and to maintain.
OrderByDescending(x => x.CreatedDate)
But you need to rewrite all view.
Hi Alex,
That works perfectly! Thank you for helping me out yet again!
Have a great day,
Jedd
You are welcome, Jedd.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Listing Articles in Date Order
Hello everyone,
I have a macro that pulls out some info from all pages with doctype 'article'
The code is as follows:
The only problem I am having, is the output is listed in order of tree position, however I want them to be showed in date order (newest first).
Is there a quick fix?
Thanks in advance!
-Jedd
postNodes.orderBy(x=>x.GetPropertyValue
Hi Jedd,
You have to add ordering as said Yasir, I would suggest for you to use createdDate field which is general for Umbraco nodes, like that:
Thanks,
Alex
Hi Jedd,
Also be aware that dynamic objects has this strange ways for sorting - OrderBy("createDate desc"). Much better will be to use strongly typed models, sorting will be much easier to understand and to maintain.
But you need to rewrite all view.
Thanks,
Alex
Hi Alex,
That works perfectly! Thank you for helping me out yet again!
Have a great day,
Jedd
You are welcome, Jedd.
Alex
is working on a reply...