Last active
October 12, 2016 16:35
-
-
Save glcheetham/5612fd1d28fd36e62638cd85105cbe0e to your computer and use it in GitHub Desktop.
Example dynamic Umbraco sitemap.xml template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage | |
@{ | |
Layout = null; | |
umbraco.library.ChangeContentType("text/xml"); | |
} | |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | |
@foreach (var root in Umbraco.TypedContentAtRoot()) | |
{ | |
<url> | |
<loc>@root.UrlAbsolute()</loc> | |
<lastmod>@root.UpdateDate.ToString("yyyy-MM-ddTHH:mm:00")+00:00</lastmod> | |
@if(root.HasValue("updateFrequency")) | |
{ | |
<changefreq>@root.GetPropertyValue("updateFrequency")</changefreq> | |
} | |
</url> | |
foreach (var content in root.Descendants().Where(c => c.GetPropertyValue<string>("noIndex", "True") == "False")) | |
{ | |
<url> | |
<loc>@content.UrlAbsolute()</loc> | |
<lastmod>@content.UpdateDate.ToString("yyyy-MM-ddTHH:mm:00")+00:00</lastmod> | |
@if (content.HasValue("updateFrequency")) | |
{ | |
<changefreq>@content.GetPropertyValue("updateFrequency")</changefreq> | |
} | |
</url> | |
} | |
} | |
</urlset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment