Matthew Groves
Matthew Groves

Reputation: 26141

How do I query for comments in Orchard?

I am trying to build a "Latest Comments" widget for Orchard CMS.

I know I could directly query the SQL, but is there an API I can use in Orchard to get the latest comments on the whole blog (and which blog post each comment belongs to, etc)? I've been looking at IContentManager::Query, but I'm not exactly clear how I can use this to get the information I want.

Upvotes: 1

Views: 245

Answers (1)

Brandon Joyce
Brandon Joyce

Reputation: 3110

Check out the CommentsService in the Orchard.Comments module. Orchard.Comments.Services.CommentsService. It's really close to what you need. Since the service returns the query, you could just tack on some additional sorting like this...

var query = commentsService.GetCommentsForCommentedContent(blogId);
var comments = query.OrderByDescending(c => c.CommentDateUtc).Slice(10);

Something like that.

Upvotes: 3

Related Questions