You can create dynamic views of your content by using the Content Query Web Part. You can customize the query that defines what content is displayed, and can customize the view settings that determine how that content is presented on the page.
In this article
What is the Content Query Web Part?
The Content Query Web Part displays a dynamic set of items based on a query that you build by using a Web browser. You use the query to specify which items are displayed, and you can set presentation options to determine how those items are displayed on the finished page.
The items that are displayed by the Content Query Web Part always reflect the most current set of items that are retrieved by the query that the page viewer is authorized to see. The query is run whenever the page that contains the Content Query Web Part is viewed. If new content is added and it meets the query criteria, it is automatically displayed by the Content Query Web Part.
Note: There may be a delay of a few minutes between the time that new content is added and when it is displayed by the Content Query Web Part.
After you add the Content Query Web Part to a page, you edit the Web Part to change which items it displays and how it displays them. To edit the Content Query Web Part, point to the Web Part, click the down arrow at the top right corner of the Web Part, and then click Edit Web Part. The tool pane opens and displays the Content Query Web Part settings.
There are five categories of settings:
-
Query Use these settings to build the query.
-
Presentation Use these settings to customize the presentation of the items that are retrieved by the query.
-
Appearance Use these settings to adjust the appearance of the Web Part itself. You can change the title, height, width, and chrome (the design and navigation elements that frame the Web Part) of the Web Part by changing these settings.
-
Layout Use these settings to adjust the layout of the Web Part. You can change whether the Web Part is visible, whether it is directional (left-to-right, right-to-left, or neither), which zone the Web Part appears in (top, left column, or right column), and the zone index of the Web Part.
-
Advanced Use these settings to adjust a variety of more advanced Web Part options.
Build a Query
You can specify which content the query retrieves by using the following Query settings.
Source This setting determines the scope of your query. This setting is required. There are three options:
-
Show items from all sites in this site collection Select this option to query the entire site collection. This is the default setting.
-
Show items from the following site and all subsites Select this option to limit the query to a particular site in the site collection. You can type the address for the site, but we recommend that you use the Browse button to select a site. When you click Browse, the Select Site Web Part dialog box opens and displays a tree view of the site collection. Click the site that you want to query, and then click OK.
-
Show items from the following list: Select this option to limit the query to a particular list or library in the site collection. You can type the address for the list, but we recommend that you use the Browse button to select a list or library. When you click Browse, the Select List or Library Web Part dialog box opens and displays a tree view of the site collection. If the list or library that you want to query is located within a particular site, click the plus sign (+) next to that site's name. When you see the list or library that you want to query, click it, and then click OK.
List Type This setting is required. You can choose any type of list that is in your site collection. The type of list that you choose determines which of the lists or libraries that are in the scope of the query are processed by the query.
Content Type There are two settings for Content Type: Content Type Group and Content Type. These settings are optional. You can use these settings to limit the query to items of particular content types that are defined for your site collection.
Audience Targeting This setting is optional. If you select Audience Targeting, the query filters the content that it retrieves to show only content that is targeted to the audience that the page viewer belongs to. Audiences are defined system-wide, and cannot be changed by using the Content Query Web Part. This setting only determines whether the Web Part respects Audience Targeting.
When you select Audience Targeting, a second setting becomes available: Include items that are not targeted. When you select this setting, any content that is not explicitly targeted to an audience is retrieved by the query, regardless of who is viewing the page. If you select Audience Targeting but do not select this setting, content that is not explicitly targeted to an audience is not retrieved by the query.Additional Filters This setting is optional. You can use this setting to further limit the content that the query retrieves. Choose a filter field, a comparison operator, and enter your criteria. For example, you can use the filter field Author, the comparison operator Is Equal To, and the criterion Toni Poe, to limit the query's results to items that were authored by Toni Poe. Filter options vary depending on the filter field that you choose. For example, if you select the Created By field, you are presented with the additional options:
-
[Me] will display content created by you.
-
Type or browse to the person, so the Web Part will display content created by them.
-
Custom Value or Query You may also enter these tokens as filter values:
-
PageFieldValue: field name – You can use this setting to filter content dynamically based on the specified field of the current page.
-
PageQueryString: query string parameter name – You can use this setting to filter content dynamically based on the value of the query string property specified in the current page URL.
Note: If the page field value or query string parameter value is null, the filter will not be included in the query.
-
You can specify up to three filters by using the Additional Filters setting. If you use more than one filter, you must specify how the filters are collectively applied by using the And and Or options that precede the second and third filter.
Note: The options under Additional Filters may vary based on the source selected.
Customize the data presentation
You can customize the presentation of the content that the query retrieves by using the following Presentation settings. All of these settings are optional.
Grouping and Sorting Use these settings to arrange the items that are retrieved by the query.
-
Group Items By Select a field to use to separate items into groups. For example, if you want to group items based on who authored them, select Author.
-
When you select a field to group by, you can specify whether the items are arranged in ascending or descending order by using the Show groups in ascending order and Show groups in descending order options.
-
Number of Columns Specify the number of columns that you want to use to arrange the items. Items can be arranged in up to five columns.
-
Sort Items By Select a field to use to sort the items. If you have specified that items are grouped, the items are sorted within those groups.
-
When you select a field to sort by, you can specify whether the items are arranged in ascending or descending order by using the Show items in ascending order and Show items in descending order options.
-
Limit the number of items to display You can limit the number of items that are displayed by setting this option. If you do not specify a limit, all items that are retrieved by the query are displayed. If there are a large number of items, the page expands to accommodate them.
Styles Use these settings to apply visual styles to groups and items.
-
Group style Select a style to apply to the group heading. For example, if you group by author, each group of items is headed by the author name, and the author name appears in the style that you specify by using this setting.
-
Item style Select a style to apply to items
Fields to display Depending on the scope of your query, you can select one or more site or list columns whose values you want to show in the display slots for this style. To specify a column from a particular group, type the name of the group in square brackets after the column name, for example, Column [Group]. Be sure to separate each column you enter with a semi-colon.
If the first column you specify has a blank value, the Web Part will show the value of the subsequent column.
Feed You can choose to have your Content by Query Web Part serve as an RSS Feed. This gives page viewers the option of subscribing to the query results of the Web Part, so that they receive new items when they appear, without having to revisit the page. Use these settings to specify a title and description for the RSS Feed.
-
Feed title Enter a name that you want to use for the RSS Feed. This name helps subscribers to identify the feed in their RSS reader.
-
Feed description Enter a description that you want to use for the RSS Feed. This description helps subscribers to identify the feed in their RSS reader.