In this SharePoint Online tutorial, we will discuss content query web part SharePoint online or SharePoint 2013/2016. We can use content query web part to display content from sites or sub sites within a SharePoint Online site collection.
Here we will discuss what is a content query web part in SharePoint Online/2013/2106? How can we enable content query web part at the site collection level? How to add a content query web part to a SharePoint Online web part page?
We will also see how we can display SharePoint Online list items on a web part page using the content query web part. How to build a query for content query web part. How to represent the retrieved content in the content query web part SharePoint Online?
We will also see various examples of content query web part, how to display list items in a content query web part in SharePoint Online, how to display subsite data using SharePoint Online content query web part. How to use a filter in the content query web part in SharePoint Online or SharePoint 2013/2016.
SharePoint Online tutorial contents:
- What is SharePoint content query web part?
- Enable content query web part in SharePoint Online/2013/2016
- Add content query web part to a web part page in SharePoint 2013/2016/Online
- SharePoint content query web part Properties
- Build a query in Content Query Web Part
- How to represent the content in the Web part page?
- Display List Items in SharePoint content query web part
- Display Subsite List Items in a content query web part
- Display List items with created by filter
- Add a filter in the Content Query Web Part
Content query web part is a web part available in SharePoint used to display the data from the SharePoint site and subsite, within a site collection in SharePoint 2013/2016/Online.
We can not use content query web part at the tenant label or admin label, we can not display data which belong to a different site collection in SharePoint.
Note: When we are trying to display SharePoint online list data then we can only display the finite list of properties such as Link, Image, Title, and description in
By default, if the SharePoint publishing feature is not activated then you can not see the Content Search web part on the web part page like below. Here we need to activate the SharePoint Server Publishing Infrastructure site collection feature.
Open SharePoint Online site, go Site Settings page. In the Site settings page Under Site Collection Administration, click
Activate the “SharePoint Server Publishing Infrastructure” in the “site collection features” page.
After this, you can able to see the “Content Query” web part in the web part list in the SharePoint online web part page.
You can activate the SharePoint server publishing feature.
Open the SharePoint online web part page. Click on “Add a web part”. From the “Catagories” select the Content Rollup -> Content Query. Click and “Add”.
After the web part is added to the “web part” page, we can customize that what is the items the web part will display and how it will represent the data.
So for that on the right side corner click on the arrow. Then click on the “Edit web part” otherwise we can directly go to the web part setting page from the “open the tool pane”.
We can customize the content query web part using the below settings option.
Query: Using the Query option we can create a build.
Presentation: Using the presentation we will see how we are presenting the item which is retrieved by the Query option in the web part page.
Appearance: The Appearance option is used to how the web part will appear in the web part page. Using the appearance we can change “Title”, “Height”, “Width”, “Chrome state”, ” Chrome type” option of web part page.
Layout: The Layout option is used to change the Layout of the content query web part in the web part page. We can change weather the web part is visible or not on the web part page, we can set the direction of web part pages such as left to right or right to left or none.
We can also change the Zone change of web part page that is in which zone the content query web part will appear in the SharePoint web part page. We can use the zone index also for the web part.
Advanced: In this Advanced settings lot of advanced setting is present for web part page like allowing to export data or not, only non sensitive data will export.
Build a query in Content Query Web Part
The content query “Query” settings contains
Source: We can do settings using below 3 option of “Source”.
Show item from all sites in this site collection: When we enable this option then the data will retrieved from the all sites but with in the site collection only.
Show items from the following site and subsite: This option when we enabled then the item will be retrieved from the site and subsite but within the site collection. In the below of this option, one text input box is present where we can give the site and subsite URL address.
Beside the text input box, we will see the browse option where we can browse the site. Best practice is to browse from the site.
Show item from the following list: When we enable this option we can display the particular list items in the SharePoint content query web part. Like above here also we can give the list URL address of SharePoint site or we can browse from the SharePoint site.
List Type: This List Type setting is displaying all the type of list available in the SharePoint site collection. The list type determines which type of list or library will display in the web part page.
Content Type: This content type setting is optional. It consist of two thing “Show items of this content type group” and “Show items of this content type”. The “All Content Types” is selected by default. We can choose the content type group from the list of content types.
“Show items of this content type”: Here we can choose the content type name from the list of content type.
Audience targeting: This “Audience Targeting” setting is optional in the content query web part. When we select “Apply audience filtering”, the query only filter the retrieve content which is targeted to audience, the audience means the page view belongs to.
Additional Filters: This settings option is optional. Here we can put the condition to display the item. Suppose one list is there in which user are adding the item. Suppose we want to display that item which is created by the logged in user.
So in the first input box, we can add “app created by” is equal to the name who created the list. We can use three conditions at a time to retrieve the item from the SharePoint site.
How to represent the content in the Web part page?
Presentation: We can customize the data which is retrieved by the query by using the Presentation settings option. This presentation setting option contains below option.
- Grouping and Sorting: By using the “Grouping” and “Sorting” option we can arrange the item which are retrved by query.
Group items By: Using the Group items by option we can grouping the retrieved item. For example, suppose we want to display all the item which is created by the list creator. We can easily be grouping the item from “Group item by” field. From the dropdown list, we will get the “created by”.
The group item by option is used to isolate the items and represent in groups. For example, if you want to group the items which is grouped by the list creator, then from the dropdown option you can easily choose the “created by”.
In the Group Items By field. we can represent the data in ascending or descending order by using below two options:
- Show group in ascending order
- Show group in descending order
A number of columns: This field is used to specify the number of columns that we want to arrange the items. The maximum we can arrange 5 columns.
Limit the number of items to display: Using this field we can limit the number of items to display. If we will not mention the Limit then all item will be retrieved on the web part page.
Styles: This field contains Group Style and Item Style.
GroupStyle: The group style is used to set the style for the group heading. In the group item by field, I have selected “Created By”. So the created by heading will also display with the item. So here we can set the heading for
Item style: This field is used to set the style for item.
Fields to display:This field contains Link, Image, Title, Description. When we are trying to represent the list item in the content query web part page we can only display the 4 column. In the Link, Image, Title, Description field we need to write the list column name.
Feed: We can choose to have the content query web part as an RSS feed. This gives an option to the page viewers to subscribing the content query result. So that they receive the new item when they appear, they need not revisit the page.
Feed Title: In the Feed Title filed enter a name for the RSS feed. Using this name the subscriber identify the feed.
Feed Description: This field is used for a description for RSS feed.
Here we will see how to display list items using content query web part in SharePoint Online or SharePoint 2013/2016. So I have created a Custom List as name “Product Review”. I have created two site column named as “Product Picture” of picture type and Product review of “Single line of text”.
The product name is by default title column, i renamed the title column. Then add to the SharePoint site “ProductReview” list.
Now I have added one content query web part to a web part page in my SharePoint Online site. After adding the web part go to the “Edit web part” page. Expand the “Query” settings. In the Source field enable the “Show items from the following list“.
Then give the list URL. But best practice is to browse the list. Click on browse. One “Select list or library” page will come. Select the List name and click on OK.
In the “Show items from this list type” field select the type of list. I have created the “ProductReview” of “Custom List”.
Go to Fields to display field of Presentation settings. Here in the input box we need to add the list column name. The “ProductPicture”, “ProductName”, “ProductionReview” are the “ProductReview” column name.
OutPut: This is how the result will appear from the SharePoint content query web part.
Display Subsite List Items in a content query web part
Now I will show, how can we show items from subsite in the site collection using content query web part in SharePoint 2013/2016/Online.
Here I have a sub site under my site collection as TsHR which has two announcement lists:
In the web part page go to the “Edit Web Part” page. Again go to “Source” field from the “Query” settings. Select the “Show items from the following site and all subsites” radio button. Give the sub site address in the next input box. Otherwise click on “Browse”, then select the sub site name.
In the List Type field, select the list type from the “Show items from this list type”. Then select the list type as “Announcement”. Here I have changed the title from the “Appearance” settings.
Display List items with created by
I have created a SharePoint calendar list known as 2019Events and added few columns in it.
So I have added one content query web part, and go for “Edit web part” page like previous example by browsing I have added the calender list in the SharePoint site. In the “Show items from this list type” choose “Calender”.
In the presentation settings
In the “Group items by” I have added the created by. Here I want to group the calander list item based on the “Created By” field. In the Short items by, I have added “Created”.
In the Style in the group style I have added “Banded”. Click on Apply and then OK.
Out Put: The output screen look like below. The list item are displaying based on created by.
Add a filter in the Content Query Web P
Here we wills see how to display list items created by the logged in user in the content query web part. Follow below steps to add filter in content query web part.
Edit the Content query web part, Expand Query and choose Additional Filters. In the “Show items when” field add “Created By” from the drop-down. In the next input box add operator “is equal to”. From the next radio button field choose [Me].
Below you can see the query displaying the items which are created by the logged in the SharePoint online calendar list.
You may like following SharePoint tutorials:
- Create Site Columns programmatically in SharePoint 2016/2013 using
ServerObject Model in Visual Studio 2017
- How to change Master Page in SharePoint 2016, SharePoint 2013 or SharePoint Online?
- SharePoint Create Subsite with Unique Permissions in SharePoint 2013/2016/Online
- Approve/Reject documents or items using Content Approval in SharePoint Online or SharePoint 2016/2013
- Add a Link to web part title in SharePoint Online/2013/2016
- SharePoint search managed properties
- How to use SharePoint date filter web part in SharePoint Online/2016/2013
- How to use Page viewer web part in SharePoint 2016/2013 or Online
- Choice Filter Web Part in SharePoint 2016/2013 or SharePoint Online with Example
- Create and Use Content type hub in SharePoint Online/2013/2016/2019
This SharePoint Online tutorial explains, What is content Query web part in SharePoint? How to add the content query web part in a web part page in SharePoint 2013/2016/Online.
In few SharePoint content query web part examples, we saw how can we display items from list or libraries presented in SharePoint subsites. Also, we saw how can we filter items by created by column in SharePoint content query web part in SharePoint 2013/2016/Online.
Hello Everyone!! I am Bhawana a SharePoint MVP and having about 10+ years of SharePoint experience as well as in .Net technologies. I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools. Now exploring more in SharePoint 2016 🙂 Hope here I can contribute and share my knowledge to the fullest. As I believe “There is no wealth like knowledge and no poverty like ignorance”