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.

  1. Go to the Page tab at the top left of the page.
  2. Select Edit page.
  3. Then go to the Insert tab.
  4. Click the Web Part button.
  5. Select the Content Rollup Category.
  6. Select the Content Search Web Part.
  7. Hit add on the right hand side.
  8. Once the web part is added to the screen you should see something like this. web-part-screen
  9. Then you will need to edit the web part by clicking in the top right corner of the web part.
  10. Select Edit Web part. This should bring up this window on the far right. edit-web-part-menu
  11. We are going to first change the query to make sure we are bringing back the correct items.
  12. Hit the Switch to Advanced Mode link in the top right. switch-to-advanced-mode
  13. 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”.
  14. 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.
  15. 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.
  16. Once you have your query finished you will need to also sort the results.
  17. We do that by clicking on the sorting navigation link along the top navigation bar in the modal window. 

  18. 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.
  19. 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.

Leave a Reply

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