Copied to clipboard

Flag this post as spam?

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


  • Pablo 2 posts 82 karma points
    Feb 25, 2016 @ 19:38
    Pablo
    0

    list all DescendantsOrSelf("NewsItem") excluding some nodes

    Hi I want to list all DescendantsOrSelf("umbNewsItem") but I want to exclude some nodes from the list that has NewsItems Can I exclude then using the Node Name, I´m trying using where clause but I have no results.

    For example I want to list all newsitems excluding the ones in Child 3 All folders has newsitems

    Home
        -Folder 1
           - Int Folder 1
              - Child 1
              - Child 2
              - Child 3
              - Child 4
          - Int Folder 2
              - Child 1
              - Child 2
              - Child 5
              - Child 6
      - Folder 2
           - Int Folder 1
             - Child 5
             - Child 6
    
    var homePage = CurrentPage.AncestorsOrSelf(1).First();
    var articles = homePage.DescendantsOrSelf("umbNewsItem").Where(XXX).OrderBy("publishDate desc, createDate desc").Take(4);
    

    What must I write in XXX ? Thanks.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 25, 2016 @ 19:52
    Dennis Aaen
    1

    Hi Pablo,

    What you could do is to add a property on your newsitem, of the type true/false data type. The alias of the property should be umbracoNaviHide.

    Then you could do this

    var homePage = CurrentPage.AncestorsOrSelf(1).First();
    var articles = homePage.DescendantsOrSelf("umbNewsItem").Where("Visible").OrderBy("publishDate desc, createDate desc").Take(4);
    

    Then It will only show the items that doesn't have a tick in the umbracoNaviHide.

    You can of course name the property what you want, the important thing is the alias of the property that needs to be umbracoNaviHide

    Hope this helps, and can be a solution.

    /Dennis

  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Feb 25, 2016 @ 20:17
    Marc Goodson
    100

    Hi Pablo

    I'd do what Dennis suggests... but out of curiosity:

    var articles = homePage.DescendantsOrSelf("umbNewsItem").Where("parent.Name != @0","Child 3").OrderBy("publishDate desc, createDate desc").Take(4);
    

    would be the sort of syntax you would need to answer your specific question...

    ie you use @0, @1, @2 parameters to substitute into your Where condition

    regards

    Marc

  • Pablo 2 posts 82 karma points
    Feb 26, 2016 @ 14:34
    Pablo
    0

    Thanks to both!!! Marc, I was trying your solution but "parent.Name" was what I need. THANKS, I was writting wrong "NodeName". Thanks again!!!

Please Sign in or register to post replies

Write your reply to:

Draft