CommunityServer: Adding the "Post Date" Sort Order

I've made a handful of modifications to the Community Server software that I use as a back-end to a website of mine (TheDailyWTF.com). Since quite a few people seem to be using this software, I thought I'd share what I've done. If you find this post valuable, let me know in the comments and I'll post more in the future.

One of the first things I noticed when switching from .TEXT to CommunityServer::Blogs Beta 2 was that it lacked the ability to sort threads by the date of the first post. Since I have a custom RSS feed that displays the ten most recent posts, this definitely would not do. So I'll explain how I added this very easy change ...

Step one is to edit the Enumerations\SortThreadsBy.cs (in CommunityServerComponents) and add the emboldened code:

public enum SortThreadsBy { 
PostDate,
LastPost,
ThreadAuthor,
TotalReplies,
TotalViews,
TotalRatings,
Subject }

Next, we need to change the data access code. This is in ForumsSqlDataProvider.cs in the SqlDataProvider class. Go the the overloaded "public override ThreadSet GetThreads" method and locate the region "#region Order By and Active Topics". Just add the following block under "switch (sortBy)":

case SortThreadsBy.PostDate:
  if (sortOrder == SortOrder.Ascending)
    orderClause.Append("PostDate");
  else
    orderClause.Append("PostDate DESC");
  break;

Finally, we need to add the option to the picklist. This change is appropriately in Controls\Utility\ThreadSortDropDownList.cs in the CommunityServerForums project. The items are added in the constructor, so you can easily modify it to this:

public ThreadSortDropDownList() {
// Add countries //
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_LastPost"), ((int) SortThreadsBy.LastPost).ToString()));
Items.Add(new ListItem("Post Date", ((int) SortThreadsBy.PostDate).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_StartedBy"), ((int) SortThreadsBy.ThreadAuthor).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_Ratings"), ((int) SortThreadsBy.TotalRatings).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_Views"), ((int) SortThreadsBy.TotalViews).ToString()));
Items.Add(new ListItem(CommunityServer.Components.ResourceManager.GetString("ThreadSortDropDownList_Replies"), ((int) SortThreadsBy.TotalReplies).ToString()));
}

Note how I didn't add it to the resource file and the subsequent code to do that. Since I don't plan on supporting more than one language on the site, there's really no need to do this.

And that's that. Told ya it was an easy modifcation ;-).

Published Friday, March 25, 2005 12:02 AM by Alex Papadimoulis
Filed under:

Comments

Friday, March 25, 2005 12:29 AM by Matt

# re: CommunityServer: Adding the "Post Date" Sort Order

Isn't "// Add countries //" a minor WTF in itself?
Friday, March 25, 2005 9:46 AM by Scott

# re: CommunityServer: Adding the "Post Date" Sort Order

What happens when they release a new CS version and you have to upgrade?
Friday, March 25, 2005 9:53 AM by Alex Papadimoulis

# re: CommunityServer: Adding the "Post Date" Sort Order

Scott,

As I did with the Forums Beta 2 changes, go through and remake every change. So long as you document your changes (I have a change log word document), it's not too painful.

This is why I won't upgrade unless the new version makes it worth while.

-- Alex
Friday, March 25, 2005 10:29 AM by patag

# re: CommunityServer: Adding the "Post Date" Sort Order

Any mods or tweaks you do, I'd love to hear about.
Saturday, March 26, 2005 1:25 AM by Tim Haines

# re: CommunityServer: Adding the "Post Date" Sort Order

Useful.
Saturday, March 26, 2005 10:08 PM by Dave Burke

# re: CommunityServer: Adding the "Post Date" Sort Order

Excellent! I would definitely love to hear about more of your CS work. Subscribed!
Monday, March 28, 2005 11:46 AM by Dave Burke

# re: CommunityServer: Adding the "Post Date" Sort Order

Alex, I was cruising along, made the mod, then went to administration to change the sort options. I don't have Forums enabled, and I see no ability to change the sort order in Admin Blog, so I'm wondering if I'm missing something? Great description of making the mod, btw. 4 minutes, tops.

Monday, March 28, 2005 11:55 AM by Alex Papadimoulis

# re: CommunityServer: Adding the "Post Date" Sort Order

Dave,

I have not looked into the blogs component at all. I have only Forums enabled, and have a custom home page that looks like a blog (but feeds from the main forum).

-- Alex
Monday, March 28, 2005 1:42 PM by Dave Burke

# re: CommunityServer: Adding the "Post Date" Sort Order

Thanks for your reply, Alex. Is this site online? Not TheDailyWTF?
Monday, March 28, 2005 1:50 PM by Alex Papadimoulis

# re: CommunityServer: Adding the "Post Date" Sort Order

This modification (and the tweaks I will continue to writeabout) are all tweaks I made for The Daily WTF.
Monday, March 28, 2005 10:56 PM by Dave Burke

# re: CommunityServer: Adding the "Post Date" Sort Order

Well I'll be! I never knew The Daily WTF was using Forums! I assumed it was a blog. Nice. I get it now. Thanks for your help clarifying the point for me.
Saturday, April 02, 2005 11:36 PM by TrackBack

# CommunityServer: Custom Homepage With Thread Listing

Sunday, April 10, 2005 2:21 AM by TrackBack

# re:CommunityServer: Adding the

^_^,Pretty Good!
Monday, April 25, 2005 2:31 AM by TrackBack

# CommunityServer: Custom Homepage With Thread Listing

In this Community Server tip, I'll describe how to make a quick & easy home page that displays posts...
Thursday, July 10, 2008 1:22 PM by hakan uzuner

# re: CommunityServer: Adding the "Post Date" Sort Order

hi ;

i change my site by your code but i have a problem ..

Leave a Comment

(required) 
(required) 
(optional)
(required)