Monday, 23 November 2009

IntenseDebate is a great free blog comments system. Here's a bit of LINQ to XML VB.NET code that will get posts from your blog that have recent comments. IntenseDebate offer a JavaScript version that will show the most popular posts over all time, but the problem with this is that it's not very customisable, doesn't allow for any ASP.NET caching and if a post gets a lot more comments than any others then it will always be at the top of the list, ignoring more recent post comments.

This code gets posts with comments from the IntenseDebate XML feed, groups them by post and selects the top eight. Use the StripOutURL function if you want to show just the basic URL for the post without the #IDComment tag that IntenseDebate adds.

Function GetPostsWithComments() As String

Dim myIDAPI As New XDocument

myIDAPI = XDocument.Load("http://www.intensedebate.com/allBlogCommentsRSS/YOUR BLOG ID HERE")

Dim Posts = (From Post In myIDAPI.Descendants("item") _
Select PostTitle = Post.Elements("title").Value, _
PostUrl = StripOutURL(Post.Elements("link").Value), _
PostCount = CInt(Post.Elements("item").Count) _
).GroupBy(Function(Poster) New String(Poster.PostTitle) _
).Take(8)

Dim sb As New StringBuilder

sb.Append("<ul>")

Dim myQuery = From c In Posts

For Each MyX In myQuery

sb.Append("<li><a href=""" & MyX.ElementAt(0).PostUrl & """ >" & MyX.ElementAt(0).PostTitle & "</a></li>")

Next

sb.Append("</ul>")

Return sb.ToString

End Function


Private Function StripOutURL(ByVal s As String) As String

Dim str As String = ""
str = Left(s, s.IndexOf("#"))

Return str

End Function



Share this webpage Comments on this webpage