This post will explain how to implement archive functionality in Sitefinity blogs, similar to the one you can see on this blog. The idea is pretty simple. We want to list all the months in a year and show many posts have been published in that month, regardless of how embarrassing sometimes that can be (take June or April on this blog for example). When user clicks on a link we want to display the list of posts published in that month.
Not in a reading mood? Download the controls right away!
To archive this you'll need three different pages in your blog. Take a look at the graphic below to see what I mean.
As you can see there are three different pages that we have :
- All posts page - this is a page where you will put two (at minimum) controls. The standard PostList control and Archive control (it is a user control which you can download at the bottom of this post)
- Single post page - this page has also two controls. The standard SinglePost control and again Archive control
- Archive posts page - this is the page that will display only posts published in a particular month of a year. Instead of using a standard PostList control you will use here ArchivePostList control, which is a user control that wraps up standard PostList control and alters it's data source to show appropriate posts.
As you may have already noticed, I have mentioned two controls that do not come with standard Sitefinity installation. These are the two user controls I have built to archive this functionality.
Archive control is the control you will have pretty much on every page. It displays month and year together with the number of posts published in that month. There are two important properties of this control :
- SelectedBlogs - determines for which blog(s) will archive be created. This allows you to have different archive controls for each blog and maybe one control that creates archive for all blogs on your site.
- ArchivePageUrl - this property sets the url of a page where you have put ArchivePostList control. This property is very similar to the ExternalSinglePostPage property of standard PostList control. Basically, you are telling control where to go when the month link is clicked.
This control is a user control which only purpose is to wrap the standard PostList control and modify it's data source to show only posts published in a particular month. There is only one property in this control, though you can modify the control to expose more of the PostList control's properties.
- ExternalSinglePostPage - this property determines the page which contains SinglePost control or in other words, where should you go when you click on the post inside of the list.
All in all it's pretty simple functionality. You will notice in the ArchivePostList control how to take advantage of the newly introduced property CustomDataSource. The two mentioned controls are commented and you can download them from here