By default, the XSL style sheet that controls the presentation of the Content Query Web Part renders the Title, Description, ImageUrl, and LinkUrl columns (if present) of the items the query returns. The Web Part renders the ImageUrl and LinkUrl columns as an image and as a hyperlink, respectively. The Content 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 need to perform some minor customization in the .webpart file.
Follow these steps in order to display custom fileds in content query web part
1. Add a Content Query Web Part to a page.
· In the Query section, set the Source to show items from the Knowledge Base Articles document library (list). Set the list type and content type accordingly.
· In the Presentation section, set the Item Style to Title and description.
2. Edit the properties in the Web Part file to display custom fields. To access the .webpart file for the Web Part, on the Web Part's edit menu, click Export.
· Office SharePoint Server 2007 generates a .webpart file with the complete set of properties that are available for this Web Part. The .webpart file is an XML file that you can edit using a text editor.
3. In the .webpart file, locate the CommonViewFields property. Use this property to specify the additional fields you want to display in the Web Part. Add the internal names of the columns and the type.
You can map above field with tile, description, image url and link url or you can use above fields in your custom style.
Please note that following are types available for data type specifications. If you specify wrong type it will not break code but field will not be displayed on site.
4. Map these internal column names to the columns' Title and Description present in the XSLT transformations. To do this, edit the DataColumnRenames property.
5. Save the .webpart file locally.
6. In the Web page, delete the Content Query Web Part you added in step 1.
7. Import the .webpart file and add the Web Part to your page. To import the .webpart file, click Page, click Add Web Parts, and then click Import. Browse to the .webpart file, and then click Upload.
8. Drag the Web Part to the appropriate zone in the page. The Web Part should display the Knowledge Base Title and the product name.
If you have added multiple fields in CommonViewFields and you need to customize XSL for this please follow steps below
· Open the site in SharePoint Designer (SPD). Navigate to Style Library, then XSL Style Sheets. Open ITEMSTYLE.XSL.
· Take a minute to look at the file. Every time you see
"> xsl:template..." that is the start of a new Item Style. There is one for each of the out-of-the-box Item Styles that show up in the Styles drop down in the Web Part Tool Pane. For every custom Item Style that is needed, a new xsl:template block will have to be created.
· Scroll down to the bottom of the file. Copy the last xsl:template code block and paste it above the closing xsl:stylesheet tag.
· Change the name and match properties in the Template tag to a unique name of your choice:
· Change following
<div class="description" >
<div class="description" >
· Repeat above with title as well and assign custom xsl using Content Query Web Part -> Presentation-> Item Style