Introduction
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="comments"> | |
Comments: <span class="comments" pageurl="{@PageUrl}"><xsl:value-of select="@PageComments" /></span> | |
</div> |
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.
The following JavaScript code demonstrates how to utilize SharePoint Web Services for retrieving comment count per page and to bind it to comments item template (ItemStyle.xsl)
Code excerpt for comment item from ItemStyle.xsl:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="comments"> | |
Comments: <span class="comments" pageurl="{@LinkUrl}"></span> | |
</div> |
Pingback: How to to retrieve and display Social Ratings in Content Query web part | Yet Another SharePoint Blog
Using the second case, how would I check if the value is 0 or nothing before showing the value?
Add this to your template that you are displaying in your CQWP and it will return all the values from your list:
=
greate post
Hi, how can i do this using content search webpart say i want to display the number of likes and number of comments. Any help appreciated.