SharePoint Blog

Adding a rating to a publishing page layout

Reading SharePoint Magazine’s pratical guide to social features in SharePoint 2010 I got curious as how I could add a rating control to a publishing page layout so that readers of an intranet portal could rate for example a news item. I turned out not to be that complicated at all.

I started by creating a new ContentType that inherits from SharePoint’s out of the box Page ContentType and added it to the Pages Library that sits in my publishing site. I then fired up SharePoint Designer, opened my publishing site and subsequently clicked the site layouts list in the left hand navigation. I clicked New Site Layout from the toolbar to create a new site layout and made sure it used my newly created ContentType. I checked out the site layout and registered SharePoint’s portal web controls like this:

<%@ Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

I wanted the rating control to appear on top of the page next to the article’s date, so I scrolled down and added the following snippet to article-header div:

    <SharePointPortalControls:AverageRatingFieldControl ID="PageRatingControl" FieldName="AverageRating" runat="server"/>

I then enabled the Rating Settings for the Pages libary:

pages library rating settings

(Click image to enlarge)

This added two columns to the list:

  • Number of Ratings
  • Rating (0-5)

I then created a new page with the following result:

publishing page layout with rating


(Click image to enlarge)

You need to be aware that the calculation of average ratings is only done at fixed intervals so it can take a while before you start seeing an average rating. If you’re very impatience, you can kick-start things by changing the settings for the following two SharePoint timer jobs:

sharepoint social data timer jobs

(Click image to enlarge)

Also note that the User Profile Service needs to be up and running.

Don’t forget to visit the SharePoint App Market

Copyright ©2012. All Rights Reserved.