Latest Posts

Content Query Web Part (CQWP) in SharePoint

In this article, we are going to look into the details about how we can use the Content Query web part in the SharePoint page, what are the different configurations, where we can use this web part and much more.

Important Notes:
  • Prerequisite for using CQWP: You need to activate the site collection level feature: SharePoint Server Publishing Infrastructure.
  • Content Query Web part directly queries the database. So, it is quicker in terms of getting the results compared to the Content Search web part.
  • When there’re frequent changes in results, you can use the Content Query Web part.
  • If you are working in SharePoint Online and your content keeps growing then you should consider CSWP instead of CQWP as it is very difficult to scale the performance up in SharePoint online for CQWP.
  • The OOB Content Query Web Part has several templates to display the results with a maximum of four fields (depends on the template you have selected.)
    • Link
    • Image
    • Title
    • Description

Add Content Query Web part on page

  • Create a web part page
  • Edit the page and click on Add a Web Part.
  • Select the Content Query web part from the Content Rollup category
  • select cqwp
  • Click on Open the tool pane or you can just edit the web part

    You can see, there’s a lot of configuration settings. We will go through each one by one.

Query:

Source:

This part decides the source of the query.

    cqwp query source
  • Show items from all sites in this site collection: This will consider all the sites from the current site collection to pull the records from.
  • Show items from the following site and all subsites: You can browse and pick a site and it will consider that site and all it’s subsites to pull the records to display in the web part.
  • Show items from the following list: You can specifically select a list to pull the records from.

List Type:

The moment you select Site from the above step, (Option 1 or 2), the values in this drop-down will populate. You can select the type of the list from the drop-down.

cqwp query listtype contenttype

Content-Type:

In the Content-Type section, in the first drop-down, Show items of this content type group: you can select the group of the content type.

In the second drop-down, Show items of this content type: all the content types belonged to the group selected in the above step, will be listed.

Include child content types: All the child content types will also be included if you tick this.

Audience targeting - Apply audience filtering:

If we tick this, the logged-in user will see only the results which are Target Audience Enabled and which are targeted to that user.

cqwp apply audience filtering

Audience targeting - Include items that are not targeted: By enabling this, you can also view the results where the target audience is not enabled.

Additional Filter:

  • You can apply three filters on the results using this section.
  • You can select filter field, filter, and filter value here and based on that the results will be filtered out and displayed here.
  • You can use AND or OR for additional filters.
  • cqwp Additional Filter

You may also enter these tokens as filter values:

  • [PageFieldValue: field name] - uses the value of the specified field of the current page.
  • [PageQueryString: query string parameter name] - uses the value of the specified query string property of the current page URL.
  • If the page field value or query string parameter value is null, the filter will not be included in the query.
  • For date fields, enter an integer value in "Custom Value or Query" to set up a dynamic date range which will be equal to [Today] + [integer value] number of days.

Presentation:

There are a few options available to modify how we want to present the data on the web part.

Grouping and Sorting:

cqwp Grouping and Sorting
  • You can apply grouping and sorting by selecting the columns from the dropdown list.
  • Both Group by and Sort by coming with Ascending and Descending order functionality. Whatever order you choose the results will be accordingly ordered.
  • Limit the number of items to display: Additionally, you can limit the number of items you want to display in the results. You can specify an integer value over here.

Styles:

cqwp styles

 

  • Group Style and Item Style: There are a few styles listed in the dropdown list, you can pick any of the styles for the entire group (Group Style) as well as for the row items (Item Style).
  • Play media links in browser: When we select this option, media (Video) will be played in the browser. If it is not selected, files are played through Windows Media Player.

Fields To display:

  • Depending on the scope of your query, select one or more sites or list columns whose values you want to show in the following display slots for this style, separating entries with a semicolon. To specify a column from a particular group, type the name of the group in square brackets after the column name. Ex: Column[Group].
  • In the OOB template, there are only four fields that you can map to the actual columns and use in the template. The templates for CQWP are in xsl file format and can be found in Site Content >> Style Library >> XSL Style Sheets. You can create your own template here.
    • Link
    • Image
    • Title
    • Description
    • cqwp Fields To display
  • If the first column you specify has a blank value, the web part will show the value of the subsequent column.

Feed:

We can choose to have an RSS feed for Content query web part results. The subscribers can use the RSS feed and the next time there’s any new result they will know without coming to this page.

cqwp feed

Feed Title and Feed Description: The setting comes with two fields. Title and Subscription. You can enter the Title and the Subscribers can use the title to get the feeds. You can also specify the feed description. Both are optional.

Conclusion:

We went through all the properties available to set for the content query web part. You can explore the properties more and accordingly set the CQWP web part.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint