Umbraco Razor List Pages of a Certain Type from Anywhere in the site

The following script takes a look through all the nodes in the umbraco structure, and lists all the nodes of a certain type: (in this case "FAQ"s - good for Front Page News)

@inherits umbraco.MacroEngines.DynamicNodeContext
    @foreach (var thisPage in @Model.Descendants("Faq").Take(5))
    {
      <li style="text-align:left;"><a href="@thisPage.Url" style="color:#ffffff">@thisPage.Name</a></li>
    }
 



To Sort by the updated date:

@inherits umbraco.MacroEngines.DynamicNodeContext


   
    @foreach (var thisPage in @Model.Descendants("Faq").OrderBy("UpdateDate descending").Take(5))
    {
      <li style="text-align:left;"><a href="@thisPage.Url" style="color:#ffffff">@thisPage.Name</a></li>
    }


 Output:

Comments

Popular posts from this blog

Umbraco Razor Sort Nodes Ascending or Descending

Umbraco Razor get Querystring

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco