It's almost the same code, but instead of listing child nodes you have to get Articles root node first and only after that -> iterate through child nodes.
I would use this code:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var homePage = Umbraco.AssignedContentItem.Site(); // get home page
var selection = homePage.Children.FirstOrDefault(x => x.DocumentTypeAlias.Equals("articlesMain") && x.IsVisible()).Children.Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate);
@* OrderBy() takes the property to sort by and optionally order desc/asc *@
}
@foreach (var item in selection)
{
<div class="article">
<div class="articletitle"><a href="@item.Url">@item.Name</a></div>
<div class="articlepreview">@Umbraco.Truncate(@item.GetPropertyValue<string>("ArticleContents"),100) <a href="@item.Url">Read More..</a></div>
</div>
<hr/>
}
List of Article Items on Homepage
I setup an Articles page very much like this tutorial: https://our.umbraco.org/documentation/tutorials/creating-basic-site/articles-parent-and-article-items
It works great. I have an Articles page that lists the children Article Items exactly like I want.
My question is, how do I pull through a list of those articles to my homepage?
I'm running v 7.7.4 if that helps any.
Thanks in advance!
Hi Bh
It's almost the same code, but instead of listing child nodes you have to get Articles root node first and only after that -> iterate through child nodes.
I would use this code:
Thanks,
Alex
is working on a reply...