Querying by document type (and child types) recursively
Hi,
I have a sort of a article setup, where I have a Article document type, and I create those articls in Date folders (auto-generated folders based on a date value).
But I also have child types derived from this article type, for example review is a child type of article. Thought I'd be smart and have this set up like so, so I could both list based on the parten type, and differentiate on the types.
So I could have a tree like this:
Home´ - 2010 - 11 - Some Article - Another Article - A Review of something (kinda like a article) - 12 - Yet anohter Article - Anohter silly Review
Let's that I want to list newsest 5 Articles (including child types). Also I'd like to just list by exact type (just the Articles and just the Reviews etc.)
Querying by document type (and child types) recursively
Hi,
I have a sort of a article setup, where I have a Article document type, and I create those articls in Date folders (auto-generated folders based on a date value).
But I also have child types derived from this article type, for example review is a child type of article. Thought I'd be smart and have this set up like so, so I could both list based on the parten type, and differentiate on the types.
So I could have a tree like this:
Home´
- 2010
- 11
- Some Article
- Another Article
- A Review of something (kinda like a article)
- 12
- Yet anohter Article
- Anohter silly Review
Let's that I want to list newsest 5 Articles (including child types). Also I'd like to just list by exact type (just the Articles and just the Reviews etc.)
Any nifty ideas ? :)
Something like this:
This will give you all of the articles.
But you can't get descendants of different node types. For that I would just put them in a generic list and do a for-each on the list:
@{ var myList = new List<umbraco.MacroEngines.DynamicNode>(); foreach (dynamic page in @Model.AncestorOrSelf(1).DescendantsOrSelf().OrderBy("CreateDate desc")) { if(page.NodeTypeAlias == "OneType" || page.NodeTypeAlias == "OtherType") { myList.Add(page); } } } @foreach(dynamic page in myList.Take(5)) { <span>@page.Name</span> }
Thanks a million, this is exactly what I needed to get a kick start! :D
is working on a reply...