YAFLogo

Slick86_98
  • Slick86_98
  • 55.4% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
Hey guys, I am trying to integrate the forum with my main page. I have a news Category that I want to show up with only the newest topics in that category. Then I also want to use on my main page as well. My forum is located in "/forum/" and when I click on a link, the page tries to postback to the calling page name in that folder instead of the forum default page in that folder. I was also wondering how to get the topics out of that specific category and show them on my main page? Any ideas?
Sponsor
Mek
  • Mek
  • 100% (Exalted)
  • YAF Developer
15 years ago
In the interests of time saving; I'm simply using the Active Discussions RSS Feed instead of using the control. But I'd be interested if someone else has got the above working.


UserPostedImage

"It's a case of RTFM.. the only problem being we don't have a manual!"

When I post FP:Mek in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Ederon 🙂 )

Slick86_98
  • Slick86_98
  • 55.4% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
I will try the rss idea. That would actually work for both of the things i am doing. Do you recommend that i use an xmldatareader or a 3rd party rss reader for asp.net? I am a pretty decent coder but i have never used rss before.
Slick86_98
  • Slick86_98
  • 55.4% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
I tried it with XMlDataReader and i kinda works. Is it possible to make the rss feed show the contents of the first post in the topic?
SSDExecutor
15 years ago
I didn't actually use that control, but I used some of the code behind it to create my own. I made a webcontrol using a datalist like this:

<asp:datalist id="dlForumPosts" runat="server">
            <alternatingitemstyle backcolor="Silver" />
            <itemtemplate>
                <div style="padding: 2px;">
                    <asp:hyperlink id="hlPost" runat="server" navigateurl='<%# "/forums/Default.aspx?g=posts&m=" & eval("LastMessageID") & "#" & eval("LastMessageID")%>'><%#Eval("Topic")%></asp:hyperlink>
                    <div style="margin-left: 10px;">
                        in <span style="font-weight: bold;">
                            <%#Eval("Forum")%></span> on
                        <%#MethodsUtility.ConvertDateToEnglish(eval("LastPosted"), True)%>
                        by
                        <%#Eval("LastUserName")%></div>
                </div>
            </itemtemplate>
        </asp:datalist>

and then added this to the Page Load method:

Dim dtActivePosts As DataTable = YAF.Classes.Data.DB.topic_latest(1, 10, Profile.YAF.UserID)
        dlForumPosts.DataSource = dtActivePosts
        dlForumPosts.DataBind()

You can see what it looks like on our front page at http://www.redstickrebellion.com/ . Hope that helps.

Slick86_98
  • Slick86_98
  • 55.4% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
Thank you! That works awesome! Do you know if there is a way to get the initial contents of the Topic post as well? I wanted to do news separate with a title and information instead of the user having to click to view it.
SSDExecutor
15 years ago
No problem Slick! If you're trying to get the text from the actual post, you need to take the LastMessageID value for each item and get it from the yaf_Message table of the YAF database. Something like this:

Add a label to the itemtempate of the datalist, like this:


       <asp:datalist id="dlForumPosts" runat="server">
            <alternatingitemstyle backcolor="Silver" />
            <itemtemplate>
                <div style="padding: 2px;">
                    <asp:hyperlink id="hlPost" runat="server" navigateurl='<%# "/forums/Default.aspx?g=posts&m=" & eval("LastMessageID") & "#" & eval("LastMessageID")%>'><%#Eval("Topic")%></asp:hyperlink>
                    <div style="margin-left: 10px;">
                        in <span style="font-weight: bold;">
                            <%#Eval("Forum")%></span> on
                        <%#MethodsUtility.ConvertDateToEnglish(eval("LastPosted"), True)%>
                        by
                        <%#Eval("LastUserName")%></div>
                </div>
                <asp:label id="lblPostContent" runat="server" />
            </itemtemplate>
        </asp:datalist>

Then add an event to the datalist's ItemDataBound event, like this:


    Protected Sub dlForumPosts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlForumPosts.ItemDataBound
        Dim dtTopic As DataTable = YAF.Classes.Data.DB.message_list(e.Item.DataItem("LastMessageID"))
        DirectCast(e.Item.FindControl("lblPostContent"), Label).Text = dtTopic.Rows(0)("Message")
    End Sub

Now, this will read from the database once for each post that you show - so if you're doing a good number of them it may be worth it to pre-load the table straight from the YAF database and just filter each time you enter the ItemDataBound method - but this should give you a good place to start. Hope that helps.

Slick86_98
  • Slick86_98
  • 55.4% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
Thanks! I had to approach it a bit differently because i am writing in C# and it would not let me do it the way you wrote it out. I ended up creating a new datatable on page load and added the message.

foreach (DataRow row in dtActivePosts.Rows)
        {
            if (!row["ForumID"].Equals(2))
            {
                row2 = newsExclude.NewRow();
                row2["LastMessageID"] = row["LastMessageID"];
                row2["Topic"] = row["Topic"];
                row2["Forum"] = row["Forum"];
                row2["LastUserName"] = row["LastUsername"];

                DataTable dtTopic = YAF.Classes.Data.DB.message_list(row["LastMessageID"]);
                DataRow row3 = dtTopic.Rows[0];
                row2["Message"] = row3["Message"].ToString();

                newsExclude.Rows.Add(row2);
            }
        }

http://www.extremeautoslo.com/upgrade