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:”

  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.


11 thoughts on “Display subsites in a WebPart

  1. Works great. However, do you know how I can change the result style so that the only thing that is returned is the Site Title? Right now it returns the Title, the web address, a sample of what it contains, and a picture preview. I don’t want any of that.

    Thanks in advance

    1. Apart of the CSWP you should be able to chose a few different ways to display your content, if none of them suit your needs you will need to create your own Display Template which there are plenty of good articles on how to do so.

  2. Love this, but I want to find a way to not show the subsites of my projects sites. So only showing sites 1 level deep. Could this be done with regex in some way with the filters

    1. Max, instead of filtering by Path and then filtering out current site title, if you just put ParentLink=”http://yoursiteurlhere”, then search will only return sites that are direct children of the url you specify. Make sure to keep the ContentClass=STS_Web, otherwise you’ll get lists and libraries from your parent site too.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s