Use SharePoint Keywords and Metadata to Display Related Content
May 27, 2011 8 Comments
A common scenario we come across when using SharePoint for web based content management is the ability to automatically find any related content associated with the current page being viewed. For example, if you are viewing a page about a particular service, you might like to include links to other pages that discuss related technologies. The good news is this scenario is very easy to achieve with SharePoint 2010 and a few configuration changes.
The key to setting this up is the used of the Enterprise Keywords column in your SharePoint Article pages and the Content Query Web Part (CQWP).
Firstly, extend your publishing page layout by adding the ‘Enterprise Keywords’ site column to appropriate content type:
NB: For this example I’m simply extending the base content type. I would strongly recommend you first create your own page layout content type.
Next, create some sample pages that, in this scenario, relate to specific technologies. When creating these pages, type your technology names in to the ‘Enterprise Keywords’ field for each page you create, in this example, I’ve created 3 pages that related to SharePoint, 1 that relates to SQL, 1 for Reporting Services and 1 for Excel all within the pages library of a ‘Test’ web.
Now we’ve got some content to reference, it’s time to create our page that describes our service and draws in the appropriate related technology pages we just created. We do this by creating a new page called ‘Service Page’, editing the page and inserting a Content Query Web Part (CQWP). For the purposes of this demo, I’ve added a table with some column descriptions and a CQWP:
Next, edit the service page properties and set the Enterprise Keyword for the service page to contain one of your technology names, in this example I’m using ‘SharePoint’:
Now modify the properties of the CQWP and set the Source list to be the library that contains the pages we’ve just created, in my example this would be ‘/Test/Pages’. Now press the ‘Apply’ button and you should see the CQWP return all the pages stored in the pages library (including our service page!).
Next we’re going to apply a custom filter to the web part to only show related content based on the ‘Enterprise Keywords’ field. Edit the CQWP properties and set the Additional Filters property as follows:
This is where the magic happens! The filter above will be applied to the pages in the library and return only those that contain an Enterprise Keyword contained in the current pages Enterprise Keyword field. This is possible as the CQWP in SharePoint 2010 allows you to define filters based on the current page fields or query string parameters. To find out more, as the web part suggests, click on the help icon for more info…
Once this filter is applied the CQWP should only return those pages that have been tagged with the keyword ‘SharePoint’:
The keen-eyed amongst you will have noticed that the above list still includes the current page ‘Service-Page’ – quite right too as we tagged it with the keyword ‘SharePoint’. If we want to remove this from the list of related content, we simply need to apply another filter:
Finally, you can adjust the presentation options to show a preview of the page content by populating the comments property for each technology page and then changing the CQWP Item Style property to ‘Title and Description’ and the ‘Fields to Display – Description’ field to ‘Comments’:
Your content page should now look like this, with your main content displayed along with related content automatically being pulled into the mix based on keyword matching!