A little more about Content Query Web Parts

Posted: January 19, 2011 in SharePoint, SharePoint 2007

A little more about Content Query Web Parts

Content Query is a Web Part that displays a dynamic set of items based on a query that you build by using a Web browser. You use the query to specify which items are displayed, and you can set presentation options to determine how those items are displayed on the finished page.

Thought it has already been discusses in many blogs, I thought of putting all together in this forum to share some tips and tricks with wider audience about CQWP.

 Some Useful Tips and links:

  • Adding Extra Columns in CQWP

By default, the XSL style sheet that controls the presentation of the Content By Query Web Part renders the Title, Description, ImageUrl, and LinkUrl columns (if present) of the items that the query returns. The Web Part renders the ImageUrl column and the LinkUrl column as an image and as a hyperlink, respectively. The Content By Query Web Part uses XSL style sheets to render these columns by default. 

If  you want to query for custom content types and render specific columns from those content types in the Web Part, you must perform some minor customization in the .webpart file. 

This logic is already described in multiple blogs so let me provide a good link which covers in details the logic for the same. This Links helps you in explaining in details how to add custom fields other then what CQWP renders. 


  • Paging The CQWP         

Paging feature in CQWP enable you to limit the number of items displayed in CQWP and provides the page numbers to click the next set of data.

Following links describes in details how to implement the paging feature:


  • Display Images instead of Text in CQWP 

This was one of the requirement from my client. Client owns a Project Management SharePoint site having multiple projects sub sites and wanted a CQWP which displays data from specific lists of all these sub site. Basically this data is the project status with respect to budget, Schedule, Resource, Risks etc with values like Under Control, Critical, High etc. Client wanted to show a specific color: Red, Green, Yellow instead of text in following manner:  

I achieved this requirement by creating a new template in style sheet using <xsl:Choose> which renders images instead of text.

<xsl:when test=”@Overall = ‘Critical Issues'”>
     <img src=”_layouts/images/Red.gif” alt=”Critical Issues”/>
<xsl:when test=”@Overall = ‘Proceeding with Caution'”>
     <img src=”_layouts/images/Orange.gif” alt=”Proceeding with Caution”/>
<xsl:when test=”@Overall = ‘On Target'”>
     <img src=”_layouts/images/ Yellow.gif” alt=”On Target”/>
    <xsl:value-of select=”@Overall”/>

Here is the custom template added in ItemStyle.xsl to give a detailed overview of how data is rendered: DashBoard_template.

Here is the final view of CQWP:

  • Sorting The CQWP

Thanks to Sudhir Kesharwani for this contribution on sorting out the CQWP.    

Please refer the post :  http://sudhirke.wordpress.com/2011/01/18/sorting-table-using-jquery/     

    Hope this blog helped you !!
  1. […] Web Part.  I consider that as the first part of this post.  Please make sure to go through “A Little More about Content Query Web Part“. The consolidation and additional column displaying part is done by Ankur Chourasia and he […]

  2. sudhirke says:

    Second part of this post talks about enabling sorting on the table :- http://sudhirke.wordpress.com/2011/01/18/sorting-table-using-jquery/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s