Copied to clipboard

Flag this post as spam?

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


  • Craig Hannon 1 post 71 karma points
    Jan 22, 2016 @ 22:56
    Craig Hannon
    0

    Macro Help

    Hi Guys,

    I wondered if you would be able to help. I currently have nested pages and what i want to do is write a query that gets the latest 5 child items from a given node id (included nested child items - so essentially all nested children not just direct children).

    For context I am currently using this: startNode.Children.Where("Visible"), but I want to exclude children that have the type LandingPage, and ensure its the latest 5 StandardPages.

    Any help is greatly appreciated.

    Regards Craig

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Jan 23, 2016 @ 11:48
    Marc Goodson
    1

    Hi Craig

    I really found the Umbraco Razor syntax cheatsheets really handy when I was trying to build more complex queries to see what is possible:

    https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    and also the documentation on Querying: https://our.umbraco.org/documentation/Reference/Templating/Mvc/querying

    So you can see there is the concept of Descendants, which will return not just the children of the node but the children of those children etc etc.

    There is an overload for Descendants which takes the 'nodeTypeAlias' of the type of content you want to return; since you only need StandardPages then I think

    startNode.Descendants("StandardPage").Where("Visible").OrderBy("CreateDate desc").Take(5)
    

    should get close to what you are after ?

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft