Bringing back the Blog Archive Dropdown

If you are upgrading your blog site from 3.7 or if you have worked with that version of Sitefinity before, you must be missing the good old-fashioned blog archive control. Believe it or not it is still one of the poorly designed controls in Sitefinity 5.x or 6.x. Hopefully that will change in the future, but meanwhile I created an exact copy of the 3.7 version of that control and made it compatible with the latest Sitefinity 5 or 6

And of course, not to forget the (missing) control designer

The code might seem pretty straightforward to you, but I would like to demonstrate the one part that does the grouping by year and month using Linq.

var blogManager = BlogsManager.GetManager();
var list = (from p in blogManager.GetBlogPosts()
    group p by new {month = p.DateCreated.Month, year = p.DateCreated.Year}
    into d
    select new ArchiveItem
               Month = d.Key.month,
               Year = d.Key.year,
               Count = d.Count()
           }).OrderByDescending(d => d.Year).ThenByDescending(d => d.Month);

The good news is, if you require another control for another content type such as News Archive, you can easily replace the manager that I am using. Yes ! it’s that simple.

Thank you Sitefinity for being so awesomely extensible.

Now go ahead and download it here.

Happy archiving !


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.