Andrew Kennel

Web Developer

Customizing the Content Query Web Part

June 11, 2008

Whew!  That was a lot of work.  I’m still working on the Sentinel Event site.  We have a group of Lists and want to have a single web part display entries from all the lists in one place.    We looked at a web part from Bamboo Solutions that does this, but a) it’s not…

Whew!  That was a lot of work.  I’m still working on the Sentinel Event site.  We have a group of Lists and want to have a single web part display entries from all the lists in one place. 

We looked at a web part from Bamboo Solutions that does this, but a) it’s not free, and b) there’s a delay from when you add an item to when it appears in the web part.

I was able to get the same sort of thing working with a content query web part, but that only showed the Title of the document, and no other information.  I spent the morning seeing what I could do to improve on this.

Here are the instructions I used: http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx

To start with, you need to take your existing content query web part and export it.  Once you have the XML file, you need to customize one of the lines to pull in additional columns.  Here’s the line in the WebPart you need to customize: Title, Text;Date, DateTime;PublishingContactName, Note;Injury, Choice;Phone, Note Note the format, it’s case sensitive, and the spaces have to be used as shown above.

Once your web part has been updated, you’ll need to upload it to your Web Part gallery.  Once there, you’ll be able to add the web part back to your page…and it won’t look any different.  To display the new columns, you need to customize you CSS.  This is found in the file ItemStyle.xsl, which is held at the Site Collection level under Style Library…XSL Style Sheets. 
I just copied an existing template and added a table for formatting.

<xsl:template name=“Andrew” match=“Row[@Style=‘Andrew’]” mode=“itemstyle”> <xsl:variable name=“SafeLinkUrl”> <xsl:call-template name=“OuterTemplate.GetSafeLink”> <xsl:with-param name=“UrlColumnName” select=“‘LinkUrl’”/> </xsl:call-template> </xsl:variable> <xsl:variable name=“DisplayTitle”> <xsl:call-template name=“OuterTemplate.GetTitle”> <xsl:with-param name=“Title” select=“@Title”/> <xsl:with-param name=“UrlColumnName” select=“‘LinkUrl’”/> </xsl:call-template> </xsl:variable> <xsl:variable name=“LinkTarget”> <xsl:if test=“@OpenInNewWindow = ‘True’” >_blank</xsl:if> </xsl:variable>

Share This Post