SOLVED

How to display only subsites under a site collection using highlighted content web part?

Copper Contributor

Hello all,

 

Before, I've used the search results web part to display all my subsites under a site collection. Now, I'm in the process of "modernizing" all the sites and I like to display a list of all the sites under a site collection. How can I achieve that with a modern web part?

 

Thanks in advance!

-Wagner

6 Replies
There isn't a way to my knowledge to get subsites, all the modern web parts are built around top level site collections as subsites haven't been recommended to use in awhile on SharePoint online.

You'll have to look for a custom spfx extension to deploy (easy to do) to accomplish this. There is a content search web part clone that might fit the bill here: https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-content-query-webpart


best response confirmed by Wagner Cox (Copper Contributor)
Solution

Hi @Wagner Cox ,

 

You should be able to use the Highlighted content Web Part to achieve this using the following settings:

 

Content

Source: This site collection

Type: All

Document type: Any

 

Filter and sort

Filter: Managed property

Find a managed property: content

Managed property name:

  • ContentClass
  • Equals
  • STS_Web

 

Cheers,

 

Grant.

Thank you @gjen020! That did the trick. I appreciate it the help. 

@gjen020 This is great!

 

Now, what if I wanted to do the same *from* a subsite, to only show subsite of the subsite?  When I do this from a subsite in my site collection, it of course list all subsites from the site collection down.  I tried changed the Source to This Site, to no avail - that only list the site the Web Part was on.

 

Thanks,

Lee

@LeeCharlebois 

 

You can try the following

 

Set your source to This site collection then instead of Filter use a Custom query and enter the following:

 

 

ContentClass:"STS_Web" AND Path:"https://tenant.sharepoint.com/sites/sitecollection/subsite" AND -Title:"Title of subsite"

 

 

ContentClass:"STS_Web"

 

will only look at webs

 

Path:"https://tenant.sharepoint.com/sites/sitecollection/subsite"

 

will ensure it only looks at the current site plus subsites within it. You just need to put your tenant, your site collection and your subsite you want to search under.

 

-Title:"Title of subsite"

 

is a quick way to hide the current site from showing up if you only want to show the subsites beneath it. Notice that it has a hyphen before Title which means exclude. Just have to be careful that no subsites contain the same title. A better option is using SPWebUrl, but it's not mapped as a managed property by default so would require some work to do that.

@gjen020 Brilliant!  Worked like a charm.

 

Last thing - to sort by Site Name or Title?

1 best response

Accepted Solutions
best response confirmed by Wagner Cox (Copper Contributor)
Solution

Hi @Wagner Cox ,

 

You should be able to use the Highlighted content Web Part to achieve this using the following settings:

 

Content

Source: This site collection

Type: All

Document type: Any

 

Filter and sort

Filter: Managed property

Find a managed property: content

Managed property name:

  • ContentClass
  • Equals
  • STS_Web

 

Cheers,

 

Grant.

View solution in original post