Welcome back to our series on how to create a SharePoint news slider, alternately called a news rotator. In part 1 we looked at how to create our custom list which houses our news/blog articles. We also learned how to create and manage custom search properties. We do this through our use of the crawled properties which we then mapped to a managed property in the SharePoint Search Service Application.
This article will focus on how to use the search content web part to surface that data and present it to our users. Many people will ask why we are using the search content web part versus the CSOM or REST services that are a part of SharePoint. We could use those services; however, when using those services you may run into issues trying to get the data across Site Collections due to cross site scripting protections built into SharePoint. Also by using the search service we are able to build our security trimming into our search results. So lets get started on configuring the content search web part.
First you will need to add it to the page you wish to present your news on.
- Go to the Page tab at the top left of the page.
- Select Edit page.
- Then go to the Insert tab.
- Click the Web Part button.
- Select the Content Rollup Category.
- Select the Content Search Web Part.
- Hit add on the right hand side.
- Once the web part is added to the screen you should see something like this.
- Then you will need to edit the web part by clicking in the top right corner of the web part.
- Select Edit Web part. This should bring up this window on the far right.
- We are going to first change the query to make sure we are bringing back the correct items.
- Hit the Switch to Advanced Mode link in the top right.
- The first task in our query is to point the path of the query to our list. So the query should start off with path:”url to the list in question”.
- Finally, we want our query to only return a list item so we will also add on to the query text the following: (IsDocument:”True” OR contentclass:”STS_ListItem”). This tells SharePoint to only return a document or a list item.
- When done we can test our query by hitting the Test Query button at the bottom of the page. Once you click that button the query should start showing the results in the right hand pane. You can add further query filters using the drop downs.
- Once you have your query finished you will need to also sort the results.
- We do that by clicking on the sorting navigation link along the top navigation bar in the modal window.
- You then can select the field you want to sort by using the sort by drop down. You can have multiple levels to the drop down by selecting the Add sort level.
- For our case we are going to sort by Published Date.
Those are the basics to configuring the search content web part. In the final series post we will create our control template and the item template for our news slider.