I am trying to display the last 5 news items. I can't manage to make it perform. Using DescendantContent on the root node (which I get by id, as I don't know any other way), the code below takes more than a second to run.
@{
var rootNode = Hive.Content.GetById("35a2c47081bd45a4bcbd9fe400ccabb0");
var actueelItems = rootNode.DescendantContent().Where(x => x.ContentType.Alias == "actueelItem").OrderByDescending(x => x.SortOrder).Take(5);
var actueelList = actueelItems.ToList();
if (actueelItems.Any())
{
<div class="greenBlock secondBlock leftCornerGreen actueel fixedHeightBlock">
<h2 class="DIN">Actueel</h2>
<table>
<tbody>
@foreach (var item in actueelItems)
{
var bentItem = item.Bend();
<tr>
<td class="datum">@bentItem.PublishingDate.ToString("dd-MM-yyyy")</td>
<td class="actueel-item"><a href="@Umbraco.GetUrl(@item)">@item.Name</a></td>
</tr>
}
</tbody>
</table>
</div>
}
}
I have tried to use the following line, only the resulting items don't have any properties such as Name or PublishingDate, and are not ordered or limited yet.
var actueelItems = rootNode.Children().Where("ContentTypeAlias == @0", "actueelItem");
How can I get the newest 5 content items of a certain content type anywhere in the tree (or in a specific node) in such a way that it performs, as well as contains the data accessible using the dot operator (item.PublishingDate)?
DescendantContent() dreadfully slow
Hi all,
I am trying to display the last 5 news items. I can't manage to make it perform. Using DescendantContent on the root node (which I get by id, as I don't know any other way), the code below takes more than a second to run.
I have tried to use the following line, only the resulting items don't have any properties such as Name or PublishingDate, and are not ordered or limited yet.
How can I get the newest 5 content items of a certain content type anywhere in the tree (or in a specific node) in such a way that it performs, as well as contains the data accessible using the dot operator (item.PublishingDate)?
you can use ChildContent() instead of Children() to return Content items, that way you can access those properties
is working on a reply...