4

I would like to access the properties of the terms that allow the term to appear in the global and current navigation. In the term store, you can find this setting under the Navigation Tab under "show in global navigation" and "show in current navigation".

I need to access these properties for each term programmatically.

Navigation Settings of a Term

I tried to get it via the page:

PublishingPage page = PublishingPage.GetPublishingPage(listItem);
if (page.IncludeInGlobalNavigation)

but this does not work since I want the setting for the term and this gives back true - even if Managed Navigation is activated and the term is not shown in the global navigation menu.

0

I just found out how to get these Settings: there are two properties in the NavigationTerm

here I have a shortened my timerJob where i create a custom sitemap.xml based on the SPFileLevel and the ExcludeFromGlobalNavigation property for example purposes:

using (SPSite site = new SPSite("http://yoursitesurl/"))
{
    PublishingSite publishingSite = new PublishingSite(site);
    SPWeb rootWeb = publishingSite.RootWeb;
    PublishingWeb rootPublishingWeb = PublishingWeb.GetPublishingWeb(rootWeb);
    PublishingWebCollection publishingWebs = rootPublishingWeb.GetPublishingWebs();
    foreach (PublishingWeb web in publishingWebs)
    {
        SPList pagesLibrary = web.PagesList;
        foreach (SPListItem listItem in pagesLibrary.GetItems())
        {
            if (listItem.Level == SPFileLevel.Published)
            {
                PublishingPage page = PublishingPage.GetPublishingPage(listItem);
                //retrieve the terms used for the navigation (this can be multiple terms)
                IList<NavigationTerm> terms = TaxonomyNavigation.GetFriendlyUrlsForListItem(listItem, false);

                if (terms.Count > 0)
                {
                    Console.WriteLine("Excluded from Global Navigation: " + terms[0].ExcludeFromGlobalNavigation);
                    //TODO: include your own sitemap.xml logic 
                }
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.