How to get at all child documents of some documents at specific level
My content structure is thus:
Home
- Static Pages
- Static Page 1
- News
- News Page 1
- Comment
- Comment Page 1
Using a partial view I'd like to pick the top 9 articles (ordered by published date / updated date) from either News and Comment. News and Comment share a common document type Articles - their children a common doc type Article. Staic Pages have their own content type.
What's the easiest way. Do I start with @CurrentPage or the content query object? Any snippets out there (guessing this has been done a zillion times, the e.g.s I have found are too simplistic)?
I'd already managed to get there (found a page on strongly types object model) - I am more comfortable with as few "magic strings" as possible, I prefer this:
const int perPage = 9;
var currentPage = Model.Content;
var pages = currentPage.Descendants("Article")
.Where(x => x.IsVisible())
.OrderByDescending(x => x.UpdateDate)
.Take(perPage)
.ToList();
I guess it's a matter of preference - ultimately both methods end up as the same sql query?
How to get at all child documents of some documents at specific level
My content structure is thus:
Home
- Static Pages
- Static Page 1
- News
- News Page 1
- Comment
- Comment Page 1
Using a partial view I'd like to pick the top 9 articles (ordered by published date / updated date) from either News and Comment. News and Comment share a common document type Articles - their children a common doc type Article. Staic Pages have their own content type.
What's the easiest way. Do I start with @CurrentPage or the content query object? Any snippets out there (guessing this has been done a zillion times, the e.g.s I have found are too simplistic)?
Hi Bobby,
You could try using XPath to find all articles at a specific level. I haven't tested it but it should point you in the right direction:
Hope that helps.
Thanks, Dan.
Hi
Good answer thanks.
I'd already managed to get there (found a page on strongly types object model) - I am more comfortable with as few "magic strings" as possible, I prefer this:
I guess it's a matter of preference - ultimately both methods end up as the same sql query?
is working on a reply...