Community Server : Simple way to group blog entries by date
I could not find a way to group blog entries by date using Community Server by Telligent Systems (Free Trial here!) so I decided to write one by simply modifying the skin (I did not want to make changes to the CS code)
Locate the Skin-EntryList.ascx page in your selected Theme and add the following:
(Note the Import Namespace Tag!)
<%@ Control %>
<%@Import namespace="CommunityServer.Blogs.Components" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<script language="C#" runat=server>
private const string CONTEXT_ITEM_KEY = "__lastDate";
private const string DATE_FORMAT = "MM/dd/yyyy";
private string RenderGroupDate(DateTime dt)
{
string lastDateString = Context.Items[CONTEXT_ITEM_KEY] as string;
string currentDateString = dt.ToString(DATE_FORMAT);
if (lastDateString != currentDateString)
{
Context.Items[CONTEXT_ITEM_KEY] = currentDateString;
return currentDateString;
}
return String.Empty;
}
</script>
Now place the databinding expression where you want the date to be rendered (Has to be somewhere inside the ItemTemplate Tag).
In my case, I placed it here:
<asp:Repeater id="EntryItems" Runat="server">
<ItemTemplate>
<%# RenderGroupDate(((WeblogPost)Container.DataItem).BloggerTime) %>
Now, the date will be rendered only once for entries posted on a given date.
Please let me know if there is an easier way. Thanks.