Using social comments in Publishing pages is pretty common scenario for SharePoint Publishing Sites. In comparison to page fields (Page Content, Title, Page Image and etc.) that are inserted into the “slots” of the page layout and associated with the content type of the publishing page, social comments are stored separately. Social comments are stored in separate DB and the comment entry is associated by the page Url on which comment has been given.
Let’s take a look at several approaches how to display social comments for Publishing pages in Content Query web part as shown on picture below.
Prerequisites: to enable social comments in Publishing pages the custom page layout with Note Board web part is used for demonstration here.
Extending Content By Query web part
In this approach the social comments are retrieved and saved in results before it is sent to the XSL transform using ProcessDataDelegate delegate of Content Query web part. For retrieving social comments, SocialCommentManager class is utilized, which represents the entry point in SharePoint object model (OM) that exposes methods to do work with social comments or notes.
So, in order to attach method for processing of social comments to a delegate ProcessDataDelegate we need to subclass Content Query web part as demonstrated below:
And the final step is to customize template for rendering item (ItemStyle.xsl) in order to render social columns (comment count per page in our case) in Content Query web part:
Utilizing SharePoint Web Services for retrieving social comment in CQWP
In this approach we are not going to subclass Content Query web part, but implement social comments retrieving and binding on the client side.
SharePoint Web Services exposes Social Data Service that provides methods for remote clients to Create, Read, Update, and Delete (CRUD) social data.
Code excerpt for comment item from ItemStyle.xsl: