Developer forum

Forum » Development » Get comment counts on subpage

Get comment counts on subpage

Casper Andersen

Hi All

Been trying to crack this for some hours now, but with no luck.


Basically i have a page with an item publisher attached to it, that just lists all my items, in this case i'm building a blog.

On each blog details page, if i use @TemplateTags() i see tons of properties.

One of them being the different comments properties, like Comments.TotalCount

But i would like for this information to be shown on my main page that lists each blog item.

I'm guessing i need to query each page inside my ItemPublisher:Items.List but after that i'm not sure how to get the information i want.


Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
This post has been marked as an answer

HI Casper

Yes - the count is only available on each page and not in the item publisher list.

You can get the comments for a page (you have the pageid in the item list):

Dynamicweb.Content.Commenting.Comment.GetComments("page", pageid, null, true).

It will load comments from database for each blog post item in your item publisher list - might be a small problem, but can be a performance issue.

As an alternative you can load comment count and average with a SQL like this for all blog post items in the list in one go:

select [CommentItemID] as PageID, count(commentid) as CommentCount, avg(commentRating) as CommentAverage from Comment where [CommentItemType] = 'page' and commentitemid IN ('123', '345') group by [CommentItemID]

Use the Dynamicweb.Data.CommandBuilder to execute it with the list of pageids you want to load comment counts from:

BR Nicolai

Votes for this answer: 1
Casper Andersen

Thank you very much Nicolai.

I will keep in mind the potential load on the system, but for now its up and working exactley like i want it to.


You must be logged in to post in the forum