If your document type for the News node has the alias "NewsOverview", then the code to get the latest 3 news items (from anywhere in your site) would be something like this:
@{
var root = Model.AncestorOrSelf(1);
var newsRoot = root.Children.Where("NodeTypeAlias == \"NewsOverview\"").FirstOrDefault();
if (newsRoot.Children.Count() > 0)
{
foreach (var newsItem in newsRoot.Children.OrderBy("CreateDate desc").Take(3))
{
<div class="newsitem">
<div class="date">@newsItem.CreateDate</div><br />
<a href="@newsItem.Url">@newsItem.Name</a>
</div>
}
}
}
Get NodeByName and browse it
Hello,
What i'm trying to do is to get my news node and take the 3 last published. the news published are child of the news node.
How could i do that ?
thank you by advance
That depends on how your site structure is set up, I am assuming it's a bit like this:
Content
- mysite.com
- Home
- TextPage
- News
- News Item 1
- News Item 2
- News Item 3
- News Item 4
- News Item 5
- News Item 6
If your document type for the News node has the alias "NewsOverview", then the code to get the latest 3 news items (from anywhere in your site) would be something like this:
Yes you rox :)
is working on a reply...