Sort BlogEngine.net Page List by Title

Here is a code snippet to sort Blogengine.net page list.
You want to modify the following C# file: BlogEngine\BlogEngine.NET\AppCode\Controls\PageList.cs
LINQ used to sort the pages and changed the Foreach loop to use the LINQ query.
private static HtmlGenericControl BindPages()
{
    var ul = new HtmlGenericControl("ul") { ID = "pagelist" };
    ul.Attributes.Add("class", "pagelist");

    //Sort pages
    var MyPages = BlogEngine.Core.Page.Pages.AsEnumerable()
        .OrderBy(x=> x.Title);
     
    //foreach (var page in BlogEngine.Core.Page.Pages.Where(page => page.ShowInList && page.IsVisibleToPublic ))
    foreach (var page in MyPages.Where(page => page.ShowInList && page.IsVisibleToPublic))
    {
        var li = new HtmlGenericControl("li");
        var href = page.RelativeLink;
        if (BlogSettings.Instance.RemoveExtensionsFromUrls && !string.IsNullOrEmpty(BlogConfig.FileExtension))
            href = href.Replace(BlogConfig.FileExtension, "");
        
        var anc = new HtmlAnchor { HRef = href, InnerHtml = page.Title, Title = page.Description };

        li.Controls.Add(anc);                
        ul.Controls.Add(li);
    }
    
    return ul;
}
Comments are closed