Hi I need to remove a section from our site from the sitemap. Right now it is outputting all content onto the sitemap. We have some ads displaying as annoucnements that shouldn't be displayed. Code is below. Any ideas?
thx
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@* Render the sitemap by passing the root node to the traverse helper *@
<div class="sitemap">
@Traverse(CurrentPage.AncestorOrSelf(1))
</div>
@* Helper method to travers through all descendants *@
@helper Traverse(dynamic node)
{
@* Update the level to reflect how deep you want the sitemap to go *@
var maxLevelForSitemap = 4;
@* Select visible children *@
var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
For the nodes you want to hide, create a property called umbracoNaviHide of data type True/False. Check this property on each of the nodes to exclude them from the code you have there. It makes the Where("Visible") code return false for that page, although I would actually reference umbracoNaviHide directly instead. I've also tweaked your sample a bit to make it more readable and conform with best practices (i.e. foreach loops with var instead of a type are harder to read or use with intellisense in Visual Studio so better to declare a type, use constants, blah blah blah :-) ). Sorry - I'm a bit retentive with that stuff
@* Render the sitemap by passing the root node to the traverse helper *@
@Traverse(CurrentPage.AncestorOrSelf(1))
@* Helper method to travers through all descendants @
@helper Traverse(dynamic node)
{
@ Update the level to reflect how deep you want the sitemap to go *@
const int maxLevelForSitemap = 4;
@* Select visible children *@
IEnumerable<IPublishedContent> items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
@* If any items are returned, render a list *@
if (items.Any())
{
<ul>
@foreach (var item in items.Where(x=>x.GetPropertyValue<bool>("umbracoNaviHide") == false))
{
<li class="[email protected]">
<a href="@item.Url">@item.Name</a>
@* Run the traverse helper again *@
@Traverse(item)
</li>
}
</ul>
}
}
How block item from sitemap
Hi I need to remove a section from our site from the sitemap. Right now it is outputting all content onto the sitemap. We have some ads displaying as annoucnements that shouldn't be displayed. Code is below. Any ideas?
thx
@inherits Umbraco.Web.Macros.PartialViewMacroPage
For the nodes you want to hide, create a property called umbracoNaviHide of data type True/False. Check this property on each of the nodes to exclude them from the code you have there. It makes the Where("Visible") code return false for that page, although I would actually reference umbracoNaviHide directly instead. I've also tweaked your sample a bit to make it more readable and conform with best practices (i.e. foreach loops with var instead of a type are harder to read or use with intellisense in Visual Studio so better to declare a type, use constants, blah blah blah :-) ). Sorry - I'm a bit retentive with that stuff
@using Umbraco.Web @inherits Umbraco.Web.Macros.PartialViewMacroPage
@* Render the sitemap by passing the root node to the traverse helper *@
@* Helper method to travers through all descendants @ @helper Traverse(dynamic node) { @ Update the level to reflect how deep you want the sitemap to go *@ const int maxLevelForSitemap = 4;
Hi I tried the navihide but it is hiding the content from appearing in my scroller as well.
is working on a reply...