Copied to clipboard

Flag this post as spam?

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


  • Brett Fullam 119 posts 629 karma points
    Jun 16, 2017 @ 18:59
    Brett Fullam
    0

    Listing news articles ... my code works ... need help changing the starting point from the 4th article not the 1st article

    I have a partial view calling-rendering the first 3 news articles using this code:

    var newsItems = CurrentPage.Site().FirstChild("articlesMain").Children("articlesItem").Where("Visible").OrderBy("CreateDate descending").Take(3);
    

    I'm trying to reuse this same code to render 4 smaller items below it pulling from the same list of articles as the line of code above. How can I pick-change the point where this starts from the 1st to the 4th item in the newsItems list?

    Appreciate the help!

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 16, 2017 @ 20:20
    Alex Skrypnyk
    1

    Hi Brett

    You code but strongly typed will look like:

    var newsItemsTyped = Umbraco.AssignedContentItem.Site().Children.FirstOrDefault(x => x.DocumentTypeAlias.Equals("articlesMain")).Children.Where(x => x.DocumentTypeAlias.Equals("articlesItem") && x.IsVisible()).OrderByDescending(x => x.CreateDate).Skip(3);
    

    It will return items except first 3. Also strongly typed is better than dynamics.

    Thanks,

    Alex

  • Brett Fullam 119 posts 629 karma points
    Jun 16, 2017 @ 20:27
    Brett Fullam
    0

    Thanks Alex ... huge help (as always).

    I'm still learning and at a break-neck pace ... Do you know of any good references for MVC you could recommend? If it's not too much trouble.

    Thanks again, man ... really appreciate it.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 16, 2017 @ 20:30
    Alex Skrypnyk
    1

    Highly recommend you read at least 5 times Common Pitfalls article - https://our.umbraco.org/documentation/reference/Common-Pitfalls/

    Here is really good resource about Umbraco - https://github.com/kgiszewski/LearnUmbraco7

    And documentation of course and Umbraco TV but I think you already know it.

    Have a great weekend,

    Alex

  • Brett Fullam 119 posts 629 karma points
    Jun 16, 2017 @ 20:38
    Brett Fullam
    0

    Perfect! I really appreciate the info ... thanks again.

Please Sign in or register to post replies

Write your reply to:

Draft