Displaying SharePoint Views with Content Search Parts

christineAdministrator Guides, SharePoint, Templates & DownloadsLeave a Comment

SharePoint keeps track of the number of views for documents, sites, and pages, and you can display this information with Content Search Web Parts (CSWP). You can use the out-of-box “Two Lines” display template to display this, but that’ll just give you the document titles and a number for the page views (unlabeled). I created a display template based off this default that adds the word “views” to the end of the view number so that it makes more sense to the users and removes the icon (it ends up using the default blank page icon for half the stuff anyway, better to hide it).

Optional: Custom Display Template

popularity-data-sharepoint3To add the word “views” to the numbers under your items, you can upload and use this display template (see these instructions for how to upload/publish display templates).

Download the HTML

Here’s what it looks like. The pager bar comes from the control “list with paging” that comes out of box, here’s what it looks like (the intranet here is called “The Commons”).

Instructions: How to Display Page Views with Content Search Web Parts (SharePoint 2013/Online)

Add a Content Search Web Part to your page. You can add multiple web parts to make an analytics dashboard, all with different queries (such one for Finance and one for Sales, one for all) to split up the data. This web part is located in the Content Rollup category. Next edit your web part settings and modify your query to what you’d like it to display popularity data on. I usually use the advanced editor here (link in top right) to manually set the query, but you can use the basic editor if it has what you’re looking for.

Useful Queries

Here’s a couple queries that I use. This one displays only sites/site collections:

contentclass:STS_Web OR contentclass:STS_Site

This one displays only pages and documents:

(FileExtension:doc OR FileExtension:docx OR FileExtension:xls OR FileExtension:xlsx OR FileExtension:ppt OR FileExtension:pptx OR FileExtension:pdf) OR (IsDocument:"True" OR contentclass:"STS_ListItem")

Omit the contentclass:”STS_ListItem” if you only want to display documents. In these queries, a colon is “contains” and an = is “equals”. There are certain properties that only works with “contains” for whatever reason, just keep that in mind.

You can limit to a site or site tree with Path: or Path=, or exclude a path with -Path: or -Path=.

The Display Templates & Mappings

When you’re done with your query, switch the control and item display templates. List or list with paging are easy choices for the control, if you’re using the custom display template above use “Two Lines – Views Line2” in the item dropdown box. Plain “two lines” will also work, but it looks a little weird.

Under Property Mappings, check the box to allow custom mappings (you may need to uncheck and check this a couple times to get it to show up, it’s buggy). Change Line 2’s mapping to one of the views statistics such as ViewsRecent (where recent is last two weeks), ViewsLifetime, or ViewsRecentUniqueUsers. I haven’t had luck with the views properties with day numbers (like Views7Days), they don’t seem accurate to me… ymmv. I like to change the name of the web part under Appearance to indicate what is being displayed as well. Click “OK” and you’re done!

Popularity Trends in Libraries

Libraries also display popularity data via a button in the ribbon. The advantage of the Content Search Web Part is that it can aggregate information from your entire environment, not just the one library. You can also control how it’s displayed via display templates – pretty cool stuff!

Leave a Reply

Your email address will not be published. Required fields are marked *