3

请给我示例或链接如何在 Sitefinity 中创建站点地图。

4

2 回答 2

4

这是我在 Sitefinity 6.1 中生成站点地图内容(页面、内置和动态)的方式。

请注意“在为内容项配置默认页面之前,您必须配置规范 URL 服务。”

  • 页面

    ISite currentSite = ((MultisiteContext) SystemManager.CurrentContext).CurrentSite;
    using (var manager = PageManager.GetManager())
    {
        var nodes = manager.GetPageNodes().Where(p =>
            p.RootNodeId == currentSite.SiteMapRootNodeId &&
            p.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard &&
            p.ShowInNavigation);
        foreach (var node in nodes)
        {
            if (!node.Page.IsBackend &&
                node.Page.Status == ContentLifecycleStatus.Live && 
                node.Page.Visible)
            {
                string host = getPageHost(serverPort, serverName, node.Page.RequireSsl);
                var url = string.Concat(host, VirtualPathUtility.ToAbsolute(node.GetFullUrl()));
                // Then append to sitemap
            }
        }
    }
    
  • 内置内容类型 - 新闻示例

    using (var manager = NewsManager.GetManager())
    {
        var newsItems = manager.GetNewsItems().Where(p => 
            p.Status == ContentLifecycleStatus.Live && p.Visible).ToList();
        // append items
        foreach (var item in newItems)
        {
            var location = SystemManager.GetContentLocationService().GetItemDefaultLocation(item);
            if (location != null)
            {
                var fullUrl = location.ItemAbsoluteUrl;
                // Then append to sitemap (if page is live/visible/frontend)                    
            }
        }
    }
    
  • 动态内容类型

    ISite currentSite = ((MultisiteContext) SystemManager.CurrentContext).CurrentSite;
    var providers = currentSite.GetProviders("YourModuleName").Select(p => p.ProviderName).ToList();
    foreach (string provider in providers)
    {       
        var dynamicType = TypeResolutionService.ResolveType("Fully.Qualified.Name.Of.Your.Dynamic.Type");
    
        if (dynamicType != null)
        {
            using (var manager = DynamicModuleManager.GetManager(providerName))
            {
                var dynamicTypeItems = manager.GetDataItems(dynamicType).Where(p =>
                    p.Status == ContentLifecycleStatus.Live && p.Visible).ToList();
                foreach (var item in dynamicTypeItems)
                {
                    var location = SystemManager.GetContentLocationService().GetItemDefaultLocation(item);
                    if (location != null)
                    {
                        var fullUrl = location.ItemAbsoluteUrl;
                        // Then append to sitemap (if page is live/visible/frontend)                    
                    }
                }
            }
        }
    }
    
于 2014-03-08T02:41:02.120 回答
3

您可以在此处使用站点地图生成器(免费): http: //enterprisefinity.com/products/sitefinity-sitemap-generator/

但是您还应该熟悉在 Sitefinity 中创建通用站点地图生成器的一些挑战。每条内容都没有设置应该出现的页面 - 这取决于您网站中小部件的配置。因此,很难构建一个解决方案来理解(例如)来自 foo 部门的新闻到这里,来自酒吧部门的新闻到那里——Sitefinity 只知道这都是新闻内容。

看看这里,更好地了解站点地图生成器背后的代码: http ://www.sitefinity.com/blogs/joshmorales/posts/11-12-22/new_sitefinity_4_4_sdk_sample_sitemap_module.aspx

于 2012-04-25T00:53:16.823 回答