SharePoint Content Query WebPart (Customizable, Powerful, and Invaluable to ANYONE who uses SharePoint)
Out of the box SharePoint provides ANYONE with almost everything you could possibly need to present SharePoint data (list items, documents, you name it..) onto a webpage. Whether you have an intranet, extranet, and/or internet SharePoint deployment one of the single most important webparts will be the SharePoint Content Query WebPart.
Not sure what it is? Basically (very generalized description) it allows you to roll up SharePoint data into a customizable presentation. Read more here: http://office.microsoft.com/en-us/sharepointdesigner/HA101741341033.aspx
What this really means is two things:
- You can roll up pretty much any kind of “query” you can think of for SharePoint data. I could roll up all the policy documents throughout the entire site collection into one page for everyone to see, or maybe roll up the latest 5 news articles and present them to the viewer.
- You can CUSTOMIZE the look and feel VERY easily. This can allow some normal list data that looks like a listing of information to be INTERACTIVE for a user, or to look and feel exactly how you want it to!
The second point there is extremely important for those who are using it for internet sites. Want your news articles to roll up on your homepage and show just a thumbnail, title and description? Easy as pie! What if those news articles are all over the site, and are made by many different kinds of users? As long as you structured the data (used content types or something) you can just “Query” it with the content query webpart and voila it will appear.
Now for the part many people miss: But it doesn’t look the way I want it to, and all the options still don’t make it look the way I want.
No problem! If you have anyone who can do basic HTML you should be able to pull it off. (XSL skills are probably a good thing for anything more advanced than minor changes.)
The Content Query WebPart runs off of XSL!
Microsoft released wonderful documentation on how to modify it here: http://msdn.microsoft.com/en-us/library/bb447557.aspx
But as always I will try and provide my own little example to help anyone who hasn’t caught on yet.
- Add a content query webpart to a page.
- Here is what mine looked like:

Take a look at the drop down for item style, what I am going to take you through is how to make your own new item style, completely customizing the LOOK and FEEL for how my data items are displayed. - Navigate to the site collection root and visit the StyleLibrary. Within this library is a folder called XSL Style Sheets. We are going to modify one of the files in here called ItemStyle.

- You can modify it in notepad, or in visual studio or some other XML/XSL editor. For this demo I will be using visual studio.
- Either write your own new template using the others as a guide OR copy one of them as a starting point. In this case we will just copy the “TitleOnly” template and paste it below.
Notice that we change the NAME and MATCH of the template we copied. This is what it will show up in the drop down as, and how it will associate the styles and xsl you adjust in the actual content query webpart. - Add some HTML or adjust the XSL as desired. In this sample I just added an image that will appear to the left of each title.

- Save and check the XSL change in.

- Open the content query webpart you added in step 1 and cause the item style drop down to display.

You will notice our new template shows up. - Click OK or Apply and VOILA – Customized Presentation (in my case an image of myself showing to the left of each item. Narcissistic I know.)

I hope you all see the power of this WebPart and use it to save you tons of time and effort,
Richard Harbridge
P.S – I highly recommend downloading and trying this solution on a development environment: http://ecqwp.codeplex.com/ which is basically a content query webpart enhanced with more properties pushed up to the user. It also has some other slick features, but basically makes the above steps far simpler to execute and adjust.
Tags: content query webpart, Presentation, RollUps, SharePoint 2007
You can comment below, or link to this permanent URL from your own site.
July 31, 2008 at 10:16 am
Hi,
This is pretty cool solution, but I have a problem. We have 4 different calendar which we “combine” with the Content Query web part. I would like to make the icons/images change depending on from which calendar the announcement is from. For instance Soccer match has a sports icon and Finace Reports announcement has finance icon.
July 31, 2008 at 10:51 am
Hello Lauri,
A quick solution to that could be to add an extra column to those lists which contains specific data. You could make this column, populate it, and set it to hidden with a default value that is say “Calendar1″. Now add a similar column to all of the calendars.
In the XSL you will have access to that column, so just now adjust the icon images based on this columns data.
That should work for what you need and requires little effort, not the best solution, but its fast and it works.
Thank you,
Richard Harbridge
March 2, 2009 at 2:35 am
i need to use a content query webpart as a field control and fetch its data into another Content query webpart.is it possible…?
March 2, 2009 at 2:38 am
i want to use content query webpart as a field control and fetch its content into another content Query Webpart.
Is it possible..?
March 2, 2009 at 8:58 am
“i need to use a content query webpart as a field control and fetch its data into another Content query webpart.is it possible…?”
A field control basically pushes data to an item’s properties.
So you definitely can fetch the data of item properties (and items) with the content query webpart.
In terms of the first part, I don’t think I understand what you are trying to do. The content query webpart basically just displays data. So it’s a read only roll up of data. A field control is typically used to store and configure data. So in my mind I cannot think of a reason that promotes business value of using a content query webpart in a field control.
That said, you can pretty much add anything with enough effort to a field control, so there’s no reason in my mind that you wouldn’t be able to add very similar functionality when you build the field control. Here’s a microsoft article on creating them: http://msdn.microsoft.com/en-us/library/aa981226.aspx
March 18, 2009 at 6:35 pm
Sorry, new to all this. Thanks for your excellent article.
How would I go about adding the Name column (i.e. the filename from a document library being queried) so it shows both Name and Title?
March 19, 2009 at 2:46 pm
So showing fields is a relatively easy thing to do. You basically export the content query webpart – open it in notepad – change one of the xml values called CommonViewFields so that includes the property you want to display (InternalColumnName, FieldType) – import it back in and it should now be available in the XSL.
In the XSL you can add lines that look like this:
P:
Which shows you all the field values. (This would go just under the itemstyle template you are using).
Ugly long process right?
My recommendation is don’t go to all this work. There is a codeplex project called enhanced content query webpart that actually rolls this xml field up into a webpart property. So instead of all that exporting/importing you would have to do for each webpart, you can just change the field in the webpart properties.
Here is an example of XSL where I am rendering fields that I added using the commonViewFields xml property.
(It’s ugly as sin, but I just wanted to a quick example for you.)
_blank
March 19, 2009 at 2:47 pm
Damn you wordpress! lol – Lets see if this works.
<xsl:template name=”CompugenQuickLinks” match=”Row[@Style='CompugenQuickLinks']” mode=”itemstyle” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:variable name=”LinkTarget”>
<xsl:if test=”@OpenInNewWindow = ‘True’”>_blank</xsl:if>
</xsl:variable>
<table cellpadding=”0″ cellspacing=”0″ id=”linkitem” style=”width:100%;font-family:Arial;”>
<tr style=”text-align:left;”>
<td style=”padding:6px 0px 2px 10px;”>
<a target=”{$LinkTarget}”>
<xsl:attribute name=”href”>
<xsl:value-of select=”substring-before(@URL,’,')” />
</xsl:attribute>
<img class=”image” src=”/_layouts/images/globe.gif” alt=”{@ImageUrlAltText}” />
</a>
</td>
<td style=”padding:6px 10px 2px 10px;font-size:11px; text-align:left; width:100%”>
<div style=”padding-bottom:2px;text-align:left;width:200px;”>
<a target=”{$LinkTarget}” title=”{@LinkToolTip}”>
<xsl:attribute name=”href”>
<xsl:value-of select=”substring-before(@URL,’,')” />
</xsl:attribute>
<xsl:value-of select=”substring-after(@URL,’,')” />
</a>
</div>
</td>
</tr>
</table>
</xsl:template>
August 24, 2009 at 1:36 pm
“Out of the box SharePoint provides ANYONE”
ANYONE? are you sure about that statement? C’mon SharePoint is a PITA, and you know it.
August 24, 2009 at 1:51 pm
Great to receive some feedback. When I say Anyone I really do mean it. I am not necessarily specifying that ‘anyone’ should be able to create the xsl templates, or update the webpart (export and re-import). When I say anyone I mean just editing the webpart on the page, configuring it’s query properties and presentation properties.
I have never in my career had a user I taught to use the content query webpart be unable to use it. In some cases it takes a bit of extra training, but tends to be well worth it.
Would love to hear what you find difficult or dislike about SharePoint more in depth. Feel free to send me messages on twitter, or comment on here.