1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Help getting top 3 posts for a forum

Help getting top 3 posts for a forum

4 posts, 0 answered
  1. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    18 Jun 2010
    Link to this post
    Hi! I am trying to get the latest 3 posts from a particular forum. I found the following code, which works great, but returns the latest 3 posts regardless of forum. I want to limit the posts to one particular forum.

    // create new instance of ForumManager
    Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
    // list of recent posts starting from the most recent one ('0')
    // and retreiving only up to three posts ('3')
    IList listOfRecentPosts = forumManager.GetRecentPosts(0, 3);
    if (listOfRecentPosts.Count > 0)
    {
       foreach (Telerik.Forums.IPost postItem in listOfRecentPosts)
           Response.Write(postItem.Content + "<br />");
    }

    Any ideas? Thanks!
  2. Johnny
    Johnny avatar
    45 posts
    Registered:
    08 Mar 2009
    19 Jun 2010
    Link to this post
    Have you looked in the dev manual for a solution?
    Basically there are a few overload methods for finding a specific forum. By guid, category etc.

    Hope this helps.
    //Johnny
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Jun 2010
    Link to this post
    Hello,

    You could use GetForumPosts(IForum parentForum) to get all posts of a particular forum and then extract only the last 3 posts. The method returns IList, so you can easily sort it with Linq.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    23 Jun 2010
    Link to this post
    I was able to get this working:

    foreach (Telerik.Forums.IPost postItem in listOfPosts)
                       if (listOfPosts.IndexOf(postItem) < 2)
                       {
                           sb2.Append("<li class=\"recent\">New Post: <a href=\"" + string.Concat("/Forums.aspx", "?mode=singleThread&thread=", postItem.Parent.ID) + "\">" + postItem.Parent.Title + "</a> on " + postItem.DateCreated.ToString(_DateTimeFormat) + " by " + postItem.Owner + "</li>");
                        }
Register for webinar
4 posts, 0 answered