Copied to clipboard

Flag this post as spam?

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


  • Emma 4 posts 75 karma points
    Oct 14, 2016 @ 14:12
    Emma
    1

    Exclude pages from showing in sitemap

    Could anybody help me to learn how to exclude certain pages from my sitemap (for example, all specials on my website I would like to remove from sitemap). Thank you in advance. Here is my code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{
    var rootNode = CurrentPage.AncestorOrself(1); }

    @Traverse(CurrentPage.AncestorOrSelf(1))

    @helper Traverse(IPublishedContent node){

    var maxLevelForSitemap = 3;
    
    var items = node.Children
        .Where("Visible")
        .Where("umbracoNaviHide != true")
        .Where("externalRedirect == \"\"")
        .Where("Level <= " + maxLevelForSitemap);
    
    if (items.Count() > 0)
    {
       <ul>
            @foreach (var item in items) {
                <li class="[email protected]">
                    <a href="@item.Url">@item.Name</a>
                        @Traverse(item)
                    </li>
                }
       </ul>
    }
    

    }

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Oct 16, 2016 @ 18:13
    Dennis Adolfi
    100

    Hi Emma. So looking at the code, the sitemap excludes all nodes that has a true value for the property "umbracoNaviHide", so you can add a property's to your "special" doctypes with the alias "umbracoNaviHide" of the datatype of a checkbox. That way you can exclude specific nodes by checking that checkbox for a specific node.

    Another way to quickly exclude a bunch of nodes of the same doctype, is to exclude a specific doctype that you don't want to have in your sitmap. For instance:

    var items = node.Children.Where("DocumentTypeAlias != aliasForTheDoctypeYouWantToEclude");

    Hope any of this information was useful to you. Hope you enjoy Umbraco so far!

    Take care! / Dennis

  • Emma 4 posts 75 karma points
    Oct 17, 2016 @ 15:39
    Emma
    1

    This worked like a charm! Thank you, Dennis.

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Oct 17, 2016 @ 17:59
    Dennis Adolfi
    0

    Glad to help! Have a great day!!! :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies