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

Forums / Developing with Sitefinity / How to display forum based on catagories?

How to display forum based on catagories?

12 posts, 0 answered
  1. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    11 Feb 2010
    Link to this post
    Hi All ,
    In the forums control i am unable to figure out how to show the forums with respect to its category, Like in News i can categorize it according to e.g Public news or private news then i can Display them accordingly by setting its value to public news or private news... In forum we can define categories but how can we display forums according to that category?

    Thanks
    Any suggestions will really be appreciated

    Regards
    Adeel Arif.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Feb 2010
    Link to this post
    Hello Adeel Arif,

    There is a method  GetForums(ICategory category, bool excludeHidden) that you can use to filter the forums by category. We do not expose a public property in ForumList or SingleForum control that you can use. You can crereate a custom contorol that extends on of the built-in controls and implement this property. Another option is working with ~/Sitefinity/ControlTemplates/Forums/ForumList.ascx template and make the filtering there by subscribing for forumsRepeater ItemDataBoundEvent where you can use GetForums method.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    12 Feb 2010
    Link to this post
    well Guyz here is what i did and it worked for me i thought that i Should post it too.


    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Forums;
    using Telerik.Forums.Data;
    using System.Collections;
      
    public partial class TestControls_GetForumByCategory : System.Web.UI.UserControl
    {
        public struct ForumData
        {
           public string Title;
           public string Name;
           public int posts;
           public int threads;
           public string last_post;
           public string redirectLink;
           public string guid;
           public string last_post_person_name;
        }
        public string CategoryName
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            #region Name=Adeel , Reason= Filter to Get Forums According to catagory...
            if (!CategoryName.Equals(string.Empty))
            {
                ForumManager manager = new ForumManager();
                IList mycatagories = manager.GetCategories();
                Category c = (from cata in (Categories)mycatagories
                              where cata.Name.Equals(CategoryName)
                              select cata).FirstOrDefault();
              
                if (c!=null)
                {
                    ICategory filterCatagory = c;
                    IList FilteredForums = manager.GetForums(filterCatagory, true);    
                    var mydata = from q in (Forums)FilteredForums
                                 select new
                                 {
                                     Title = q.Name,
                                     Name = q.Category.Name
                                     ,
                                     posts = q.PostsCount,
                                     threads = q.ThreadsCount,
                                     last_post = (from l in q.Posts
                                                  orderby l.DateCreated descending
                                                  select l.DateCreated).First().ToShortDateString(),
                                     last_post_person_name = (from l in q.Posts
                                                              orderby l.DateCreated descending
                                                              select l.Owner).First(),
                                     guid = q.ID.ToString()
                                 };
                    if (mydata != null)
                    {
                        Repeater1.DataSource = mydata;
                        Repeater1.DataBind();
                    }
                }
            }
            #endregion
        }
       
    }
    this is the cs file.....

    And for the ascx file i just used the repeater and formatted it.

     

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="GetForumByCategory.ascx.cs" Inherits="TestControls_GetForumByCategory" %>
    <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
      
     <span id="ctl00_ContentPlaceHolder5_Forums1">
               <h2 style="color: Gray;" class="sf_forumCategoryTitle"><asp:Label ID="lblName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Name")%>'></asp:Label>
    </h2
            <div>
        <table cellspacing="0" border="0" style="border-collapse: collapse;" class="sf_forumsList">
            <tbody><tr>
                <td style="width: 150px;" class="sf_forumTitle">
                            <a style="font-size: xx-small;" href='<%#"CustomerForum.aspx?mode=singleForum&forum="+DataBinder.Eval(Container.DataItem,"guid")%>'><asp:Label ID="lblheading" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Title")%>'></asp:Label></a>
                            <div style="font-size: 10px; font-family: Verdana; color: rgb(204, 204, 204);">
                           <font color="#aaaaaa"
                             
                           </font>                       
                           </div>
                        </td><td style="width: 325px;">
                       <div style="font-family: Verdana; font-size: 9px; color: Gray;">
                            <span style="font-size: xx-small;">Last post: </span>                       
                              
                                    <asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"last_post_person_name")%>'></asp:Label>
                                </span>
                              
                            <a></a>
                            <span style="font-size: xx-small;">on <asp:Label ID="lbllastpostdate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"last_post")%>'></asp:Label></span>                       
                              
                               
                              
                            </div>    
                        </td><td style="font-size: xx-small;"><asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"posts")%>'></asp:Label>
     posts</td><td style="font-size: xx-small;"><asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"threads")%>'> </asp:Label>
     threads</td><td class="sf_forumAuthor">
                         
                        </td>
            </tr>
        </tbody></table>
    </div>
      
    </span>
      
      
      
      
      
      
      
      
    </ItemTemplate>
    </asp:Repeater>

    Thanks to telerik team for Helping out.
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Feb 2010
    Link to this post
    Hello Adeel Arif,

    Thank you for sharing your code. I am sure that our community members will find it useful.

    Sincerely yours,
    Radoslav Georgiev
    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.
  5. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    08 Jul 2011
    Link to this post
    Hi Adeel

    I've just tried implementing your code of SF3.7 SP4

    I'm getting an error on the Select New line
    "Sequence contains no elements"

    it seems my data isn't null, and when it tries to databind on the repeater I get the error
    Did you ever have an issue like this?

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Jul 2011
    Link to this post
    Hi Markus,

    Check whether FilteredForums  is not null.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    11 Jul 2011
    Link to this post
    Thanks Ivan

    It's not Null

    What i'm actually trying to do is show recent posts on a selected Category

    I have the following code, but just need help with .GetRecentPosts


    ForumManager manager = new ForumManager();
    IList mycatagories = manager.GetCategories();
     
    //get selected categories
    Category c = (from cata in (Categories)mycatagories
                          where cata.Name.Equals(CategoryName)
                          select cata).FirstOrDefault();
     
     
     if (c != null) {
       
      //here i need to get the recent posts of the selected categories but unsure how
     
      // this just gets all the posts
      IList posts = manager.GetRecentPosts(0, 10);
     
    }
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Jul 2011
    Link to this post
    Hello Markus,

    I checked the code and GetRecentPosts should return the last 10 post you created.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    11 Jul 2011
    Link to this post
    Thanks Ivan

    Yes it does
    However, I also have a category (i.e. ForSale) which i want applied to the latest posts list

    this is the bit that isn't working, its just returning ALL latests posts from ALL forums

    How would I get it to return all Latests Posts from the Specified Category?

    Thanks
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jul 2011
    Link to this post
    Hi Markus,

    The Category is not a property of the IPost - the post. It is a property of IForum - the forum. So you need to get the parent which contains the category.

    below is a sample code that illustrates this.

    ForumManager manager = new ForumManager();
                var category = manager.GetCategories().Cast<Telerik.Forums.ICategory>().Where(c => c.Name == "a").SingleOrDefault();
                if (category != null)
                {
                    var forums = manager.GetForums(category, true);
                    if (forums.Count > 0)
                    {
                        foreach (IForum f in forums)
                        {
                            var fID = f.ID;
                            var posts = manager.GetRecentPosts(0, 10).Cast<IPost>().Where(p => p.ForumID.ID == fID);
                        }
                    }
                }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    12 Jul 2011
    Link to this post
    Thanks Ivan thats great

    I can see when debugging that posts has a value of
    {System.Linq.Enumerable.WhereEnumerableIterator<Telerik.Forums.IPost>}

    however I have to drill down to "non-public members/source/source to see each post

    I'm not entirely sure how to code that
    I wanted to say 
     foreach (IPost singlePost in posts)
    but obviously that doesn't work

    What code would I need to get this to drill down to the above?
  12. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    12 Jul 2011
    Link to this post
    actually don't worry it seems to work fine 

    Thanks for your help Ivan!
Register for webinar
12 posts, 0 answered