Office 365, SharePoint, SharePoint 2013, SharePoint Online

Display subsites in a WebPart

The Aim of this Article is to cover a scenario quite simple yet commonly needed and unknown that is how to display a list of subsites in a WebPart with the capabilities to filter out specific sites etc.

In this scenario I’m going to build out a Project site with project subsite underneath for which we want to display.

I now have my scenario setup that under the Projects site I would like to display each project site in a WebPart with a link to the site.

Let’s begin –

We will need to put the page into edit mode so we can add the WebPart, on the right hand side of the page click EDIT

Now the Page is in edit mode we can add the Content Search WebPart

On the SharePoint Ribbon click Insert, Select Content Rollup as the category, select the Content Search WebPart and finally click Add for it to be added to your page.

By default you will see some random content that realistically is going to mean nothing to you, our challenge is now to display a list of your SubSites in this WebPart


Select the newly added content search  WebPart and click Edit Web Part, this will load down the full set of Web part Properties in the right hand zone


In the Web Part Properties click change query

This will load up the Content Search ‘Build Your Query’ Dialog, in what in previous versions of SharePoint was a difficult task is made quite easy with the Query Builder

Once the Query Builder is open by default there are some basic options available, in this scenario we want to bypass these basic options and go straight into advanced mode

Select Switch to Advanced Mode

So to recap our scenario we want to display all the project sites available,
In the Query text enter path:”https://paradyne.sharepoint.com/sites/jdbdemo/Projects

  1. Make sure to replace the path url with your root site.
  2. On the Keyword filter drop down list select only return sites and click Add Keyword filter

If you click Test query you will notice all my available Projects are now listed in the Search Result Preview

Cool right? One issue though, it is currently displaying my Projects root site which I don’t want to show so let’s add a property filter so that’s no longer displayed.

There are various ways to do this but in this scenario I’m going to say where the Site Title is not equal to ‘Projects’ and Add Property filter

If I test my Query now this is what it shows, Fantastic.. But the order is all wrong


Click the Sorting Tab
Select Sort by: and change to Created and choose Ascending – click OK


On your Content Search WebPart click Apply.

And you’re now complete, you can play with the Display Templates to make the search results apply to your scenario but having the functionality to display each subsite in a list as originally set out.

Advertisements