Display data from multiple lists with the Content Query Web Part

Wouldn't it be nice if there was a way to query and display data from multiple lists? For example, wouldn't it be great if there was a way to display a list of links to all of the documents in all of the document libraries throughout your site collection? Better yet, wouldn't it be great if you could display a list of links to all of the documents that were modified by you or by another specified user, or to group the list by a common field that exists in all of the lists?

All of My Documents list

If you have a Microsoft Office SharePoint Server 2007 site, those things are not only nice — they are possible. You can display links to list items:

  • Throughout your site collection.
  • In one specific site and all of its subsites.
  • In one specific list.

To do this, you insert the Content Query Web Part. This Web Part can be inserted on any Web Part Page, but it can also be added to a page layout from which publishing pages are created. By adding the Content Query Web Part to a page layout, you can make the results of the query appear on every publishing page that is created from that page layout. To learn more about page layouts, see the article Create a publishing page layout.

This article shows you how to insert the Content Query Web Part into a page layout and how to customize the query to suit your needs.

 Important   The Content Query Web Part is available only in sites that are located on a server running Office SharePoint Server 2007. The server administrator must make this Web Part available in the Web Parts Gallery of the top-level site in the site collection. Also, you must have authoring permissions for the top-level site in order to open and edit page layouts.

What do you want to do?


Locate and open the page layout

You can insert the Content Query Web Part into a publishing page layout. You should first identify the page layout you want to use.

  1. Browse to the publishing site, click Site Actions, and then click Create Page.
  2. In the Page Layout section, scroll through the available page layouts for the site, and make a note of the name of the one you want to use.
  3. In Microsoft Office SharePoint Designer 2007, open the site that contains the page layout where you want to insert the Web Part.
  4. Click the plus sign (+) next to the _catalogs folder to expand it, click the plus sign (+) next to the masterpages folder to expand it, and then double-click the page layout into which you want to insert the Content Query Web Part.

The page layout opens for editing.

 Note   Page layouts have an .aspx file extension. If the page layout that you are looking for is not in the list of .aspx files, right-click each file, and then click Properties on the shortcut menu. The name that appears in the Page Layout list in the browser is displayed in the Title box for each page layout.

Top of Page Top of Page

Insert the Content Query Web Part

Now that the page layout into which you want to insert the Web Part is open, you can insert the Content Query Web Part.

  1. With the page layout open in Office SharePoint Designer 2007, click the placeholder in which you want to add content, click the arrow that appears, and then click Create Custom Content to unlock the placeholder for editing.

Placeholder showing Common Content Tasks list

  1. On the Task Panes menu, click Web Parts.
  2. In the Web Parts task pane, browse the gallery for your Web site, such as the Fabrikam Publishing Gallery, for the Content Query Web Part.

Web Parts task pane with Content Query Web Part selected

 Notes 

  • Make sure that you are viewing Web Parts from the correct gallery and that the filter is set correctly.
  • If the Web Part is not available, contact your server administrator, who can make it available by adding it to the Web Part Gallery of the top-level site.
  1. Drag the Content Query Web Part onto the content placeholder. The Web Part is inserted in the page.
  2. To preview the page layout with the Content Query Web Part in it, click Preview in browser on the Common toolbar. The page is displayed in the browser. By default, the query displays all lists, libraries, and pages in the site.

Page layout showing Content Query Web Part

Top of Page Top of Page

Customize the query

At this point, the Content Query Web Part has been inserted into the page layout, but its power is not realized until you customize the query to suit your needs. By using the Content Query Web Part, you can query a whole site collection, or any one site and all of its subsites, or just one list. You can query by list type and content type. Best of all, you can create filters for the query such that results are returned only when the list items satisfy the criteria that you specify. Finally, you can choose how query results are displayed, both by grouping and sorting them and by limiting how items are displayed from the query results.

The Content Query Web Part always displays the most current set of retrieved items that the current user who is viewing the page is authorized to see. The query is run whenever the page that contains the Content Query Web Part is displayed in the browser. Whenever new content that meets the query criteria is added, it is automatically displayed by the Content Query Web Part when the page is displayed or you click Refresh in the browser.

Do the following to customize the Content Query Web Part for specific applications. The techniques demonstrated here can help you create a wide variety of queries that can be used in a wide variety of applications.

Display all of the announcements lists in the site collection

  1. With the page layout open in Design view, double-click the Content Query Web Part.
  2. In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
  3. In the List Type section, in the Show items from this list type list, click Announcements.
  4. Click OK.
  5. To preview the page layout with the Content Query Web Part in it, click Preview in browser on the Common toolbar.

The page appears in the browser, displaying a list of links to every announcements list from every site in the site collection.

Page layout showing customized query

Display a list of links to all documents modified by the user viewing the site

  1. With the page layout open in Design view, double-click the Content Query Web Part.
  2. In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
  3. In the Source section, click Show items from all sites in this site collection.
  4. In List Type section, in the Show items from this list type, click Document Library.
  5. In the Content Type section, in the Show items of this content type group list, click Document Content Types.
  6. In the Content Type section, in the Show items of this content type list, click Document.
  7. In the Additional Filters section, under Show Items When, click Modified By in the first box, click Equal To in the second box, and then click [Me].

In this example, [Me] is a variable that stands for the user who is currently viewing the page that contains the Content Query Web Part in the browser.

Dialog box showing Additional Filters section

  1. Click OK.
  2. To preview the page layout with the Content Query Web Part in it, click Preview in browser on the Common toolbar. The page appears in the browser, displaying a list of all the documents last modified by you that reside in document libraries throughout the site collection.

All of My Documents list

Display a list of links to all graphics in the site, grouped by width

  1. With the page layout open in Design view, double-click the Content Query Web Part.
  2. In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
  3. In the Source section, click Show items from all sites in this site collection.
  4. In the List Type section, in the Show items from this list type list, click Picture Library.
  5. In the Content Type section, in the Show items from this list type group list, click <All Content Types>.
  6. Click the plus sign (+) next to Presentation to expand it.
  7. In the Grouping and Sorting section, in the Group items by list, click Picture Width.
  8. Click OK.
  9. To preview the page layout with the Content Query Web Part in it, click Preview on the Common toolbar.

Page layout showing query results

Top of Page Top of Page

 
 
Applies to:
SharePoint Designer 2007