Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • bh 108 posts 367 karma points
    Nov 13, 2017 @ 16:58

    List of Article Items on Homepage

    I setup an Articles page very much like this tutorial:

    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!

  • Alex Skrypnyk 4694 posts 16791 karma points MVP 2x admin
    Nov 13, 2017 @ 17:50
    Alex Skrypnyk

    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:

    @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>



Please Sign in or register to post replies

Write your reply to: