1

How to show the list of Subsites in a Site Collection in a 3 column format in SharePoint 2013 Site Collection landing page?

for example:

Subsite1 Subsite6 Subsite11

Subsite2 Subsite7 Subsite12

Subsite3 Subsite8 Subsite13

Subsite4 Subsite9 Subsite14

Subsite5 Subsite10 Subsite15

Kindly let me know which Web Part I have to use in order to show the list of Subsites in a Site Collection in a 3 column format

Thanks in advance.

  • I doubt you have any OOTB webpart which cater your requirement. You might need to build a custom webpart, which holds custom code may be in JavaScript or C#. – Asad Refai Mar 17 '16 at 8:53
  • Use content search web part and implement the all the subsites from the site collection, enter the querytext in the right pane's of this web part . – SaMolPP Mar 17 '16 at 9:09
0

You can use below mentioned code in custom webpart to get SubSites from site collection. Yo can get all site collection names in table as per your desired output which you want.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    //To get all subsites, use this two lines
    SPSite oSiteCollection = SPContext.Current.Site;
    SPWebCollection collWebs = oSiteCollection.AllWebs;

    //To get first subsites, use this two lines
    //SPWeb oWebsiteColl = new SPSite(SPContext.Current.Web.Url).OpenWeb();
    //SPWebCollection collWebs = oWebsiteColl.Webs;

    foreach (SPWeb oWebsite in collWebs)
    {
        using (oWebsite)
        {
           string WebURL = oWebsite.ServerRelativeUrl;
           //Code here to aarange them in table as per your need.
        }
    }
});
  • above code is heavy and uses custom visual web part . best way is to use content search web part. – SaMolPP Mar 17 '16 at 9:09
0

You can use REST API for this, you can use jquery to create tables and add the result in each cell

In order to get the list of sub sites from a site we need to call the below URL:

/_api/site/rootWeb/webinfos

Now to get the entire site structure we will need to loop every site to see if there are any sub sites present.

Below is the code I have used.

//The First Ajax is to get the Root Site Title and the Relative URL

$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + “/_api/site/rootweb?$select=Title,ServerRelativeUrl”,
method: “GET”,
headers: {
“Accept”: “application/json; odata=verbose”
},
success: function(rootsite) {

},
error: function(rootsite) {},
async: false
});

// The Second AJAX is to get all the sub sites under the Root Site

$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + “/_api/web/webinfos?$select=ServerRelativeUrl,Title”,
method: “GET”,
headers: {
“Accept”: “application/json; odata=verbose”
},
success: function(subsites) {
$.each(subsites.d.results, function() {
getSubSites(this.ServerRelativeUrl, this.Title);
});

},
error: function(subsites) {},
async: false
});

// This is a Recursive Function to loop through the sub sites and check for more sub sites

function getSubSites(SubSiteUrl, SubSiteTitle) {
console.log(SubSiteUrl);
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + SubSiteUrl + “/_api/web/webinfos?$select=ServerRelativeUrl,Title”,
method: “GET”,
headers: {
“Accept”: “application/json; odata=verbose”
},
success: function(subsites) {

$.each(subsites.d.results, function(index) {
getSubSites(this.ServerRelativeUrl, this.Title);
});
},
error: function(subsites) {},
async: false
});
}

Reference link :

Retrieve toplevel site's subsites using REST _api

http://dsouzajoel.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.