Share Point 2013 has many out-of-the-box web parts and one of them, i.e. a widely used web part is Content Query Web Part (CQWP). ContentByQuryWebpat referred to as Content Query Web Part (CQWP) is used to display content using query/filter from another site or sub-site within the same site collection. With the CQWP, content display as per the requirement, branding and context can be controlled. CQWP style sheets reside in a folder “XSL Style Sheets” in the Style Library. ItemStyle.xsl file named under “XSL Style Sheets” folder contains the style templates which can applied on-the-fly to the items returned by CQWP.
Create custom style by making a copy of ItemStyle.xsl file and make changes as required to it. Upload the customized xsl file to the style library and publish it.
Note : The Content Query Web Part is only supported in publishing sites. So, you must have the publishing features enabled to make use of it.
Limitations:
- Aggregate data only within a single site collection.
- Aggregate only list information.
Imagine that we have a requirement to display list data across sub-sites in a site collection. For instance we need to make use of a list to retrieve respective employee biographies across sub-sites in a site collection. Let me explain the scenario:
For instance the below hierarchy of share point site collections:
The requirement is to display upcoming events from a calendar in all sub-sites under communities’ site collection. We have a column named community which is used to filter and type will be choice in the same calendar list which is created as “Upcoming events” at communities site collection level. Please see the below picture for reference:
Customizing the ItemStyle XSLT file in Share Point 2013
- Open the site collection URL and Open the XSL Style Sheets folder to view the Itemstyle.xsl file.
- Download the ItemStyle.xsl file to your computer. Edit that file using notepad or share point designer 2013
- Copy the below code block and paste it above the closing </xsl:stylesheet> Here the first HTML Table row and the second HTML table row represents the column headings and the actual data respectively.
Make sure that you use this code block to output a header in XSLT:
- Save the file, upload the updated file to XSL Style Sheets folder in Style Library folder. Publish a Major Version to see the changes in the itemstyle.
Customizing the content query web part properties configuration in Share Point 2013
- Open Share Point 2013 page, where you wanted to add web part and click Site Actions, and then click Edit Page. The page will displayed in edit mode as depicted in below screen.
In Editing Tools chose insert Web Part and click “Content Rollup” Category then select “Content Query” showing in parts and click Add button. Refer the below screen
- Web part will be shown as below and customize the web part properties using “Edit Web Part” context option as directed in the below reference
- Customize the web part properties under query section, select Show items from the following list radio button and click browse button. Select List or Library pop up will be displayed and select the “UpcomingEvents” list. Refer the below screen shot.