Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve 26 posts 46 karma points
    Apr 08, 2015 @ 23:34
    Steve
    0

    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

    @* 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);
        @* If any items are returned, render a list *@
        if (items.Any())
        {
            <ul>
                @foreach (var item in items)
                {
                    <li class="[email protected]">
                        <a href="@item.Url">@item.Name</a>
                        @* Run the traverse helper again *@
                        @Traverse(item)
                    </li>
                }
            </ul>
        }
    }
  • Chris Randle 85 posts 199 karma points c-trib
    Apr 09, 2015 @ 01:18
    Chris Randle
    0

    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.Core.Models
    

    @using Umbraco.Web @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @* 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>
    }
    }
    
  • Steve 26 posts 46 karma points
    Apr 09, 2015 @ 18:11
    Steve
    0

    Hi I tried the navihide but it is hiding the content from appearing in my scroller as well.

Please Sign in or register to post replies

Write your reply to:

Draft