Try our conversational search powered by Generative AI!

explude some pages in sitemap


Hi ,

In sitemap page i can include a excludeproperty to exclude pages to display in sitemap.

how to exclude those pages. below is my property.

            GroupName = SystemTabNames.Content,
            Order = 2)]
        [AllowedTypes(new Type[] { typeof(PageData) })]
        public virtual IList<ContentReference> ExcludePages { get; set; }

Mar 08, 2021 11:28

You have a custom sitemap implementation and want to exclude som pages? Could you share some more of your code? From your controller, perhaps?

Something like this? 

var sitemapContent = _contentRepository.GetDescendents(ContentReference.StartPage).Except(currentpage.ExcludePages);
Mar 09, 2021 4:00

Create a Class for example "SitemapPage" and Add ExcludePages property in this class.

Inherit all page types with the SitemapPage class. 

To get all pages where ExcludePages is false

foreach (var site in _siteDefinitionrepository.List()) // If you have multi site
                var startPage = site.StartPage;
                if (ContentReference.IsNullOrEmpty(startPage)) { continue; }
                var xmlSitemap = _contentRepository.GetChildren<SitemapPage>(startPage).FirstOrDefault(x => x.CheckPublishedStatus(PagePublishedStatus.Published) && !x. ExcludePages );
                if (xmlSitemap == null) { continue; }
// create site map of pages in "list"
Mar 09, 2021 21:01

The code snippets provided by Tomas & Naveed are excellent examples. For sitemap logic, I have seen pages having a ExcludeFromSitemap boolean property instead of a list of pages to exclude (I guess) at the root level. That way you can filter at the page level with a predicate like :

GetDescendents().Where(x => !x.ExcludeFromSitemap)
Mar 17, 2021 13:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.