Just like with recent forum posts, it can be useful to be able to render the latest blog posts on a different page other than the aggregate page. This mini-article will outline the basic steps needed to create a control similar to what is used on the front page on www.windowsadvice.com.
Again reflector (or the CS source) is your friend in figuring out how it all works in CommunityServer internals. In this particular case, all you need is already in use on the blogs aggregate page (CommunityServer.Blogs.Controls.AggregatePostList). The code below is more or less just a copy of what is already found in CS, so no credits to me.
The needed references:
using CommunityServer.Blogs.Components; // BlogThreadQuery among other things
using CommunityServer.Components; // the ThreadSet object
The code:
// Contstruct query for getting threads
BlogThreadQuery query = new BlogThreadQuery();
query.BlogPostType = BlogPostType.Post;
query.BlogThreadType = BlogThreadType.Recent;
query.IncludeCategories = false;
query.IsPublished = true;
query.PageIndex = 0;
query.PageSize = 10;
query.SortBy = BlogThreadSortBy.MostRecent;
query.SortOrder = SortOrder.Descending;
query.FilterByList = Sections.FilterByAccessControl(
Weblogs.GetWeblogs(CSContext.Current.User,false,true,false),
Permission.View);
ThreadSet ts = WeblogPosts.GetBlogThreads(query,true,true);
ArrayList threads = ts.Threads;
The threads variable will now contain (up to) the last 10 published posts that the current user has view access to. The ArrayList can be bound to any bindable control, and as always (or, like last time anyway) I’ve provided a simple but working UserControl that you can experiment with yourself. Download it here.
Let me know if you have any questions, and I will see if I can’t add another episode to this mini-series :)