After removing the blog posts web part on the home page of a SharePoint 2010 blog site, you may have noticed that there isn’t a simple way to get it back. There isn’t a web part in the Web Part Gallery to quickly and easily add it back or even add it to another page. You can, however, do this with PowerShell (or with C# if you wanted to). The web part displayed on the home pages of blog sites are Xslt List Web Parts. Adding the blog posts web part to a page in the blog site requires adding the Xslt List Web Part, defining the list view and configuring the XSL transform file. Using the PowerShells script below will create the web part and configure it for the posts list in the blog site.

Blog Posts Web Part

Adding the Blog Posts Web Part with PowerShell

[powershell]# Get the SPWeb representing the SharePoint blog site

$web = Get-SPWeb "http://sharepoint/blog"

# Get the Default.aspx SPFile object

$file = $web.GetFile("default.aspx")

# Get the web part manager for the Default.aspx page

$wpm = $file.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

# Create a new XsltListViewWebPart object

$xlvwp = New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart

$xlvwp.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::None

$xlvwp.AllowClose = $false

$xlvwp.AllowConnect = $true

$xlvwp.ManualRefresh = $false

$xlvwp.ListName = $web.Lists.TryGetList("Posts").ID.ToString()

$xlvwp.ViewId = 0

$xlvwp.GhostedXslLink = "blog.xsl"

$xlvwp.ListId = $web.Lists.TryGetList("Posts").ID

# Defined the view for the XsltListViewWebPart

$sb = New-Object System.Text.StringBuilder

$sb.Append("<View Name='{B46A0923-68A5-42D8-815D-B615DE5CBCDB}’ ModerationType=’HideUnapproved’ FreeForm=’TRUE’ CssStyleSheet=’blog.css’ Type=’HTML’ Hidden=’TRUE’ DisplayName=” Url=’/MyBlog/default.aspx’ Level=’1′ BaseViewID=’0′ ContentTypeID=’0x’ ImageUrl=’/_layouts/images/posts.png’>")



$sb.Append("<FieldRef Name=’PublishedDate’ Ascending=’FALSE’/>")

$sb.Append("<FieldRef Name=’ID’ Ascending=’FALSE’/>")




$sb.Append("<FieldRef Name=’Title’/>")

$sb.Append("<FieldRef Name=’Body’/>")

$sb.Append("<FieldRef Name=’Author’/>")

$sb.Append("<FieldRef Name=’PostedByWithDate’/>")

$sb.Append("<FieldRef Name=’CategoryWithLink’/>")

$sb.Append("<FieldRef Name=’CategoryWithLink’/>")

$sb.Append("<FieldRef Name=’Permalink’/>")

$sb.Append("<FieldRef Name=’CategoryWithLink’/>")

$sb.Append("<FieldRef Name=’EmailPostLink’/>")

$sb.Append("<FieldRef Name=’NumCommentsWithLink’/>")

$sb.Append("<FieldRef Name=’PublishedDate’/>")

$sb.Append("<FieldRef Name=’PostCategory’/>")


$sb.Append("<RowLimit Paged=’TRUE’>30</RowLimit>")

$sb.Append("<Toolbar Type=’Standard’/>")


$xmldifinition = $sb.ToString()

$xlvwp.XmlDefinition = $xmldifinition

# Add the web part to the Default.aspx page in the Left web part zone

$wpm.AddWebPart($xlvwp, "left", 0)

# Update and dispose of the SPWeb object



Hopefully you find this useful.

Pin It on Pinterest

Share This
%d bloggers like this: