Created
May 17, 2024 20:41
-
-
Save ChrisHammond/7863717a110784387c28f7df40ab9bc1 to your computer and use it in GitHub Desktop.
This is a CommunityServer enhancement for latest forum posts from a blog post from 2004
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control %> | |
<%@ Import namespace="CommunityServer.Discussions.Components" %> | |
<%@ Import namespace="CommunityServer.Components" %> | |
<%@ Import namespace="System.Data.SqlTypes" %> | |
<script language="C#" runat="server"> | |
//This control was originally based on a blog post by Christian Nordbakk you can find it at the URL below. | |
//http://www.windowsadvice.com/blogs/cnordbakk/archive/2005/03/28/Latest_Forum_Posts_UserControl.aspx | |
//You are free to do with this code what you wish. If you wish to credit me you can link to my blog at | |
//http://www.chrishammond.com/ | |
//There is no support or warranty provided with this code, use at your own risk. | |
void Page_Load(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
ThreadSet threads = Threads.GetThreads( | |
-1, // Pick from all forums | |
0, // Return the first results | |
20, // Return 20 records | |
CSContext.Current.User, // Use the context of the current user | |
DateTime.MinValue, // Select from all threads, no matter age | |
SortThreadsBy.LastPost, // Order the result by date | |
SortOrder.Descending, // in descending order | |
ThreadStatus.NotSet, // return only from open topics | |
ThreadUsersFilter.All, // return threads posted by all users | |
true, // Return not only topics marked as 'active' | |
false, // Return not only unread posts | |
false, // Also return threads with replies | |
false // Do not bother with returning a record count | |
); | |
// Bind the returned threads to the repeater | |
PostList.DataSource = threads.Threads; | |
PostList.DataBind(); | |
} | |
} | |
int getPageNumber(int replies) | |
{ | |
int page = 1; | |
if (replies > CSContext.Current.SiteSettings.PostsPerPage) | |
{ | |
page = 1 + replies / CSContext.Current.SiteSettings.PostsPerPage; | |
} | |
return page; | |
} | |
</script> | |
<asp:Repeater id="PostList" runat="server"> | |
<HeaderTemplate> | |
<table cellpadding="3" cellspacing="0" border="0" class="tableBorder" > | |
</HeaderTemplate> | |
<ItemTemplate> | |
<tr><td class="fh4"> | |
<strong><a href="<%# Globals.GetSiteUrls().PostPaged((int) DataBinder.Eval(Container.DataItem, "MostRecentPostID"), getPageNumber((int)DataBinder.Eval(Container.DataItem, "replies")))%>"><%# DataBinder.Eval(Container.DataItem, "Subject").ToString() %></a> | |
</strong> | |
- <strong><%# DataBinder.Eval(Container.DataItem, "MostRecentPostAuthor") %></strong> | |
<br /> in <a href="<%# ForumUrls.Instance().Forum( ((Thread) Container.DataItem).SectionID ) %>"> | |
<%# DataBinder.Eval(Container.DataItem, "Forum.Name") %> | |
</a> | |
(<%# ((Thread) Container.DataItem).Replies.ToString() %> replies) | |
</td></tr> | |
</ItemTemplate> | |
<FooterTemplate> | |
</table> | |
</FooterTemplate> | |
</asp:Repeater> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment