Skip to main content

How to: Customize the Content Query Web Part by using Custom ...

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Bookmark History

Saved by 3 people (-2 private), first by anonymouse user on 2008-06-03


Public Sticky notes

QueryOverride, ListsOverride, WebsOverride, and ViewFieldsOverride Properties

Each override property—QueryOverride, ListsOverride, WebsOverride, and ViewFieldsOverride—overrides a default Content Query Web Part behavior. To override a behavior, construct a CAML query that defines the conditions you want to set.

NoteNote:

To learn more about CAML syntax and commands, see the Collaborative Application Markup Language Core Schemas in the Windows SharePoint Services 3.0 SDK.

In the following example, we demonstrate setting custom properties for the Content Query Web Part using a CAML query. The CAML query does the following:

  1. Retrieves a Created field.

  2. Sets the query to retrieve items updated in the past seven days and sorts them in descending order.

  3. Specifies the list type to query from.

  4. Retrieves data recursively from the specified Web site and its children.

  5. Retrieves values for a specific field to display for each item.

The whole query is shown, and it is described in detail in the following sections.

 1 <ViewFields>
 2   <FieldRef Name="Title" Nullable="True" Type="Text"/>
 3   <FieldRef Name="Comments" Nullable="True" Type="Note"/>
 4 </ViewFields>
 5 <Lists ServerTemplate="850"></Lists>
 6 <Webs Recursive="True" />
 7 <RowLimit>15</RowLimit>
 8 <![CDATA[
 9    <Where>
10     <Gt>
11       <FieldRef Name="Created" Nullable="True" Type="DateTime"/>
12       <Value Type="DateTime"><Today OffsetDays="-7"/></Value>
13     </Gt>
14   </Where>
15   <OrderBy>
16       <FieldRef Name="Created" Nullable="True" Type="DateTime"
17       Ascending="FALSE"/>
18   </OrderBy>]]> 

Highlighted by overhols

ListsOverride property

You can also use a CAML query to retrieve items from Windows SharePoint Services 3.0 and Office SharePoint Server 2007 lists. The following table shows three CAML statement examples that retrieve items from distinct list types.

List Type Property Statement

Page Libraries

<![CDATA[
   <Lists ServerTemplate="850">
   </Lists>
]]>

General List base type

<![CDATA[
         <Lists BaseType="0">
         </Lists>
]]>

A specific type of list

<![CDATA[
   <Lists>
     <List ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"/>
   </Lists>
]]>

In the example, Line 5 defines the ListsOverride property.

5 <Lists ServerTemplate="850"></Lists>

Highlighted by overhols