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 - Reset the Admin Password via SQL Server

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

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version