explude some pages in sitemap

Vote:
 

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.


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

#249720
Mar 08, 2021 11:28
Vote:
 

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);
#249753
Mar 09, 2021 4:00
Vote:
 

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; }
                list.Add(xmlSitemap);
            }
// create site map of pages in "list"
#249784
Mar 09, 2021 21:01
Vote:
 

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)
#250767
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.