当我在Episerver中对页面进行排序时,其也会影响网站。意味着网站页面也改变了排序顺序。
我们如何在Episerver中对页面顺序进行排序,而不会影响网站页面的排序顺序。
episerver中是否有任何配置或设置?
答案 0 :(得分:1)
假设您有一个PageDataCollection
,则使用FilterSort
类
示例
// your pages
PageDataCollection _newsPageItems;
FilterForVisitor.Filter(_newsPageItems);
new FilterSort(FilterSortOrder.PublishedDescending).Filter(_newsPageItems);
// The _newsPageItems are now filtered and sorted
这是从Episerver排序和保护所列信息的标准方法,另请阅读文章Searching for pages based on page type
考虑到您使用DataFactory来获取包含页面的列表,您可以从Enumerable<PageData>
对象实例构建PageDataCollection
使用DataFactory
也是不好的做法,您也应该使用FilterForVisitor
。我建议的实现是
// Construct an IContentLoader, this can also be done using Dependency Injection
var loader = ServiceLocator.Current.GetInstance<IContentLoader>();
// Get the children of your reference
var children = loader.GetChildren<PageData>(pageLink, LanguageSelector.AutoDetect(true));
// Construct new PageDataCollection and filter for visitor
var sortableChildren = EPiServer.Filters.FilterForVisitor.Filter(children);
// Sort
FilterSort sortFilter = new FilterSort(FilterSortOrder.CreatedDescending);
sortFilter.Sort(sortableChildren);