Lesson 2: Using the Content By Query Web Part
Although the Content By Query Web Part hasn’t changed much in SharePoint 2010, it still remains a very powerful tool that you can use to display content in a compelling way. The Lync marketing site in the screenshot below uses the Content By Query Web Part to display product-related videos.
The section of the page with the red box around it displays videos stored in a SharePoint list. When a user clicks the arrows at either end of the video list, the Web Part brings the next video into view and asynchronously loads the corresponding image, as the next screenshot shows.
The product video section employs an out-of-the-box Content By Query Web Part that uses custom Extensible Style Language (XSL) code to format the data it displays. The scrolling effect is accomplished with JQuery.
In more complex scenarios, you can develop custom Web Parts that inherit from the Content By Query Web Part. A perfect example is the Web Parts in the Visio marketing website shot you see below.
The green box highlights an out-of-the-box Content By Query Web Part configured to display sorting criteria and apply them to the page.
The two red boxes highlight custom Web Parts that inherit from the Content By Query Web Part. The custom Web Part on the left provides metadata-based filtering capabilities. It queries the SharePoint Managed Metadata Service to retrieve and display terms in the term store for the content on the page.
The custom Web Part on the right displays the filtered items. All three Web Parts on the page use custom XSL code to define their look and feel.
It’s important to understand how Content By Query Web Parts behave in anonymous access scenarios.
First, be aware that you shouldn’t link to specific list items from Content By Query Web Parts because the ability for anonymous users to view form pages isn’t enabled, even when anonymous access is enabled on the SharePoint website. However, you can turn on this functionality programmatically.
You also need to be aware that the Content By Query Web Part’s CopyUtil functionality will break if the lockdown feature is enabled. (CopyUtil.aspx is found under the _layouts virtual directory.)
To work around this problem, target all the links in your Content Query Web Part to publishing pages in your SharePoint websites.
See Lesson 3 from Todd Baginski: Learn How to Allow Anonymous Users to Rate Content
Go to Lesson 1: Pay Attention to Page Size
Check out Todd's back story on how he learned this.