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
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!
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:
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="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>
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted