Developer forum

Forum » Development » Get all descendant pages

Get all descendant pages

Søren Mastrup
Reply

I am trying to get the 5 latest articles from a set og categories.
Currently I am using this code to get the children of a certain page, but this only get the categories and not the articles:

@{
    Dynamicweb.Content.PageCollection articlePages = Dynamicweb.Content.Page.GetPagesByParentID(31);
}
<ul>
    @foreach(var page in articlePages.Where(x => x.Active).Take(5)){
        <li>
            <a href="/Default.aspx?ID=@page.ID" title="@page.MenuText">@page.MenuText</a>
        </li>
    }
</ul>

This is my page structure:

  • Article top page
    • Article Category 1
      • Article
      • Article
    • Article Category 2
      • Article
      • Article
    • Article Category 3
      • Article
      • Article

How can I get all articles, from all categories, in the same loop and sort them by date?


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Søren

Tak a look at this example on Github:

https://github.com/dynamicweb/dwtc15/blob/master/mri/Files/Templates/Designs/Dwtc15/Partials/_Navigation.cshtml

 

You must be logged in to post in the forum