The Content Query Web Part is one of the most powerful web parts which is provided by the SharePoint Server Publishing Framework (it is not available with SharePoint Foundation). It allows you to roll up information within a SharePoint site collection for display on a web page by letting you build queries through simple configuration of the different available web part properties. The Content Query web part leverages caching and performance optimization techniques and avoids the use of custom code.
While the out of the box CQWP is quite powerful you will see some that in most cases you will need extra configuration and customization. This has however become a lot simpler in SharePoint 2010 by the introduction of slots. So how does this work. Steps to get going:
- Create a new item style template file e.g. customitemstyle.xsl and upload it to the style library – see How to: Customize styles in SharePoint Server 2010 for a more detailed description. In this example I created a new itemstyle template
- Configure your Content Query web part using the different properties in the web part pane
- Export the configured Content Query web part to your desktop and modify the .webpart file. Change the ItemXsLink property and point it to the previously uploaded customitemstyle.xsl
<property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/customitemstyle.xsl</property>
- Upload the web part definition again and add it to the page. Click “edit web part” and open the web part tool pane. You will notice that within the Presentation> Styles section, you are able to select the newly created itemstyle template that you added in customitemstyle.xsl. After selecting it and clicking apply you will notice that the “CreatedBy” marker that you specified in your custom item style template is now appearing within the tool pane. These markers within the item style are called slots and can be filled with content at runtime.
Once you define slots in the itemstyle.xsl these are picked up by the Content Query Web Part and shown in the web part tool pane so that you can map these to specific fields. Using the “slots” concept you can define reusable XSL templates. This also means that you don’t need to use the “CommonViewfields” property anymore as defined in SharePoint Server 2007 – this is a thing of the past (See Displaying Custom Fields in Content Query Web Parts in Office SharePoint Server 2007)
If you want to delve a little deeper and see some practical examples of the Content Query Web Part check out these links:
- What’s new with the Content Query Web Part in SharePoint 2010
- Displaying a links lists in the CQWP (SP2010)
- Content Query Web Part – Common Enhancements
- XSLT Point – some XSL stylesheets to debug Content Query WebPart, Summary Links WebPart and Table of Contents WebPart
- Generating short description using the Content Query Web Part
- Adding table headers and or footers to a Content Query Web part
- Display News pages with CQWP – Part I